@menapo/vi18n 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/{apply-Bre-lY9J.js → apply-Bg-3rB2m.js} +69 -89
- package/dist/{captured-Bj8bO6vd.js → captured-DfLk50Ji.js} +196 -217
- package/dist/{check-BIKEuu6B.js → check-CunekuYs.js} +76 -85
- package/dist/cli.js +2 -3
- package/dist/{collect-Cx4_SKOe.js → collect-CYATDjdo.js} +1 -2
- package/dist/collisions-CDSdtLQm.js +215 -0
- package/dist/{compile-Cc97JaW2.js → compile-DqkofbiO.js} +376 -331
- package/dist/compile-hva0qjhZ.js +240 -0
- package/dist/concurrency-BCY_4zcr.js +1 -0
- package/dist/concurrency-Dy2ny50V.js +107 -0
- package/dist/config.d.ts +1 -5
- package/dist/config.js +4 -5
- package/dist/{types-D3QGM8XO.js → diagnostics-LgIWyeSp.js} +28 -27
- package/dist/{dir-zw6bGMKQ.js → dir-TGLYuOZb.js} +34 -37
- package/dist/{duplicates-yuRljQ6h.js → duplicates-8cudcHNj.js} +10 -27
- package/dist/engine-ecRD8-IE.js +556 -0
- package/dist/engine.d.ts +1 -5
- package/dist/engine.js +297 -168
- package/dist/exchange-DjwlrTQ9.js +41 -0
- package/dist/{exclude-Du-Zd_qI.js → exclude-BFETmvde.js} +2 -3
- package/dist/{export-C9Sy6UWv.js → export-D2tsqWIr.js} +17 -38
- package/dist/{extract-C3S8btx0.js → extract-BxYchVmY.js} +114 -82
- package/dist/{formats-9unqj_fZ.js → formats-BaryZ2N7.js} +352 -276
- package/dist/fs-ezCMZeDV.js +52 -0
- package/dist/i18next-COO6o0tX.js +1907 -0
- package/dist/i18next-Dr7DCQlQ.js +1 -0
- package/dist/{import-nANvQutw.js → import-vSC29Cn4.js} +81 -75
- package/dist/index.d.ts +1 -13
- package/dist/index.js +14 -16
- package/dist/{init-C2ScuW6a.js → init-Cc7A-8VX.js} +466 -501
- package/dist/{library-D5CWvTQs.js → library-tp_xqzSY.js} +975 -451
- package/dist/lingui-BnnlqGXT.js +902 -0
- package/dist/lint.d.ts +0 -4
- package/dist/lint.js +70 -82
- package/dist/{load-gW-oJt1Q.js → load-BSIeGJ5v.js} +275 -148
- package/dist/{load-CQRz4PpM.js → load-SSrAeJVB.js} +1214 -1116
- package/dist/{locales-DX4MOBFE.js → locales-D0U-yVRm.js} +271 -237
- package/dist/{lsp-RMMMc88P.js → lsp-DvC11pBZ.js} +4 -5
- package/dist/{match-BGr8EXB3.js → match-BLDcj610.js} +11 -4
- package/dist/{mcp-CHVwBoRP.js → mcp-D2zzOTBy.js} +4 -5
- package/dist/{merge-driver-BTX87aVm.js → merge-driver-BLI8OtAc.js} +138 -122
- package/dist/migrate-1r43OBfe.js +1 -0
- package/dist/migrate-ChDGhlC-.js +2169 -0
- package/dist/{openai-CTaMDcl-.js → openai-CLn4puY8.js} +128 -87
- package/dist/{output-DWE3SIUA.js → output-D5tAt8q4.js} +15 -9
- package/dist/parse.d.ts +1 -3
- package/dist/parse.js +7 -8
- package/dist/{pipeline-C9Dbotkh.js → pipeline-BJSkkRYC.js} +387 -359
- package/dist/{pipeline-DbX6rlo5.js → pipeline-BeCc441z.js} +1 -1
- package/dist/project-B5KIO0q-.js +544 -0
- package/dist/{pseudo-DRv30iN5.js → pseudo-B2DUpoLu.js} +126 -3
- package/dist/{raw-C4Y6vyGY.js → raw-YsYZMS9n.js} +52 -29
- package/dist/react-intl-C8JehBBL.js +634 -0
- package/dist/rename-ZVGq9ZG1.js +577 -0
- package/dist/repeated-uuI1tUGg.js +85 -0
- package/dist/restore-xlBIrtRt.js +199 -0
- package/dist/rewrite-BwzXoBiA.js +415 -0
- package/dist/{rich-DCUKl5HM.js → rich-ApY1Dm4S.js} +35 -28
- package/dist/rolldown-runtime-C1I3wEg2.js +43 -0
- package/dist/{rolldown-runtime-D7D4PA-g.js → rolldown-runtime-D8jQpDG7.js} +1 -2
- package/dist/run-CQ9pDLSa.js +674 -0
- package/dist/scan-worker.d.ts +2 -4
- package/dist/scan-worker.js +1 -1
- package/dist/{scoped-BMYpSthj.js → scoped-h3KE8XWW.js} +3 -4
- package/dist/{server-Da1Ot9IN.js → server-Br8tAuG2.js} +312 -386
- package/dist/{server-deBOq2vq.js → server-DJRpUQVZ.js} +1059 -333
- package/dist/server.d.ts +1 -17
- package/dist/server.js +419 -379
- package/dist/{sitemap-DJXzKoza.js → sitemap-CSAkm6oi.js} +21 -33
- package/dist/{sources-D19czDSA.js → sources-DNVbYsgs.js} +713 -373
- package/dist/{status-zr4jY59Y.js → status-q6M3rBrh.js} +30 -30
- package/dist/{stdio-FPOKQAgu.js → stdio-D9kTzyqB.js} +2 -4
- package/dist/{stdio-CVaJfxA7.js → stdio-FWIVU3P4.js} +1 -2
- package/dist/sync-BNIAwMhR.js +1352 -0
- package/dist/{t-DC-c9zE5.js → t-gvEXx25s.js} +76 -53
- package/dist/test.d.ts +5 -16
- package/dist/test.js +126 -56
- package/dist/translate-BP4iVhOR.js +336 -0
- package/dist/{ts-BaU5yOf0.js → ts-BX6kwig5.js} +25 -14
- package/dist/{types-DtvQ7UdD.js → types-3kwyaCAm.js} +1 -2
- package/dist/{types-DsdWBG0b.d.ts → types-B4wNX6PA.d.ts} +6 -8
- package/dist/{types-CgUCkFU1.d.ts → types-_4UdFhR9.d.ts} +24 -21
- package/dist/types-xR2exI3L.js +42 -0
- package/dist/{units-CQ5Q99RC.js → units-DPPfCN7j.js} +7 -16
- package/dist/{url-CRfCOhUI.js → url-Bpc6wLea.js} +24 -11
- package/dist/{url-CsBkRaJy.js → url-D2_VlEeH.js} +25 -12
- package/dist/{validate-BxpupdAf.js → validate-CgzaDdOY.js} +690 -377
- package/dist/{validate-D6DJepZv.js → validate-PGgMsasz.js} +3 -5
- package/dist/{version-Byqi2guX.js → version-DC-J5WvV.js} +3 -5
- package/dist/{vite-scan-CT_vsp4g.js → vite-scan-kM8Ta3rO.js} +87 -92
- package/dist/vite.d.ts +2 -6
- package/dist/vite.js +6500 -6032
- package/dist/vue-i18n-_uIXlFVh.js +806 -0
- package/dist/{which-BOemZ5Q8.js → which-DFWk_KwN.js} +44 -37
- package/dist/{worker-84U6uYB3.js → worker-zlhNj4y3.js} +454 -608
- package/package.json +5 -5
- package/dist/check-HsmmpJZg.js +0 -1
- package/dist/codec-DuvU2VQy.js +0 -207
- package/dist/collisions-CfpZU8e4.js +0 -217
- package/dist/compile-BaDh0cHG.js +0 -245
- package/dist/concurrency-C9UUWuDC.js +0 -96
- package/dist/concurrency-DONL7t4V.js +0 -1
- package/dist/engine-C2ENBRJe.js +0 -531
- package/dist/i18next-9HAoxwUI.js +0 -1
- package/dist/i18next-BEJgv_S8.js +0 -1596
- package/dist/lingui-zUiCl9Um.js +0 -833
- package/dist/messages-BfjIExyB.js +0 -166
- package/dist/migrate-IpLDMXmq.js +0 -1484
- package/dist/migrate-rCQuOGsf.js +0 -1
- package/dist/project-Bw9UPIdx.js +0 -1046
- package/dist/project-C4GpaN-n.js +0 -381
- package/dist/react-intl-BP0u-D5m.js +0 -519
- package/dist/restore-CiYv-jxS.js +0 -175
- package/dist/rewrite-EsIw_lsq.js +0 -803
- package/dist/run-BEcnBbu-.js +0 -694
- package/dist/runtime-DTMmliT1.js +0 -64
- package/dist/sync-B9V2KFwb.js +0 -658
- package/dist/translate-CQnJfLjO.js +0 -299
- package/dist/types-wSh9fCBY.js +0 -11
- package/dist/vue-i18n-g0iGy6CZ.js +0 -651
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { a as DEFAULT_IMPORT_SOURCES, i as DEFAULT_CONFIG, o as ID_LENGTH, r as CONFIG_FILE, s as PSEUDO_LOCALES, t as diagnosticError } from "./diagnostics-LgIWyeSp.js";
|
|
2
|
+
import { d as toPosix } from "./validate-CgzaDdOY.js";
|
|
3
|
+
import { P as displayPath } from "./library-tp_xqzSY.js";
|
|
4
|
+
import { t as excludeKind } from "./exclude-BFETmvde.js";
|
|
5
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
4
6
|
import { readFile, stat } from "node:fs/promises";
|
|
5
7
|
import { pathToFileURL } from "node:url";
|
|
6
8
|
import { z } from "zod";
|
|
7
|
-
|
|
9
|
+
// src/core/config/schema.ts
|
|
8
10
|
/**
|
|
9
11
|
* The zod 4 schema of `vi18n.config.ts` (PLAN §5.7, INTERNALS §2.7.1). It
|
|
10
12
|
* checks shapes and per-field rules only; rules that relate two keys
|
|
@@ -74,8 +76,6 @@ const RAW_TEXT = /* @__PURE__ */ new Set([
|
|
|
74
76
|
"xmp"
|
|
75
77
|
]);
|
|
76
78
|
const element = z.string().regex(/^[a-z][a-z\d-]*$/, { error: "an HTML element name in lower case" }).refine((name) => !RAW_TEXT.has(name), { error: "must render its children as text (not script, style, iframe or noscript)" });
|
|
77
|
-
/** PLAN §5.20: batches of 40–80 items. */
|
|
78
|
-
const BATCH_SIZE_RANGE = "must be an integer from 40 to 80";
|
|
79
79
|
const text = z.string().min(1, { error: "must be a non-empty string" });
|
|
80
80
|
const locale = z.string().superRefine((value, ctx) => {
|
|
81
81
|
const problem = localeProblem(value);
|
|
@@ -85,6 +85,11 @@ const locale = z.string().superRefine((value, ctx) => {
|
|
|
85
85
|
});
|
|
86
86
|
});
|
|
87
87
|
const positiveInt = z.number({ error: "must be a positive integer" }).int({ error: "must be a positive integer" }).positive({ error: "must be a positive integer" });
|
|
88
|
+
/** An integer from `min` to `max`, every failure reported with the one message naming the range. */
|
|
89
|
+
function intIn(min, max) {
|
|
90
|
+
const error = `must be an integer from ${min} to ${max}`;
|
|
91
|
+
return z.number({ error }).int({ error }).min(min, { error }).max(max, { error });
|
|
92
|
+
}
|
|
88
93
|
const withLocale = z.string().includes("{locale}", { error: "must contain {locale}" });
|
|
89
94
|
const manifestPath = withLocale.refine((path) => path.indexOf("{locale}", path.indexOf("{locale}") + 1) < 0, { error: "must contain {locale} exactly once" });
|
|
90
95
|
const routePattern = z.string().startsWith("/", { error: "route patterns start with /" });
|
|
@@ -121,7 +126,7 @@ const outputSchema = z.strictObject({
|
|
|
121
126
|
const configSchema = z.strictObject({
|
|
122
127
|
sourceLocale: locale.optional(),
|
|
123
128
|
locales: z.array(locale).min(1, { error: "must list at least one locale" }).optional(),
|
|
124
|
-
pseudoLocales: z.array(z.enum(
|
|
129
|
+
pseudoLocales: z.array(z.enum(PSEUDO_LOCALES)).optional(),
|
|
125
130
|
fallbacks: z.record(locale, z.array(locale)).optional(),
|
|
126
131
|
project: z.strictObject({
|
|
127
132
|
include: z.array(text).optional(),
|
|
@@ -133,9 +138,10 @@ const configSchema = z.strictObject({
|
|
|
133
138
|
aliases: z.array(text).optional(),
|
|
134
139
|
globals: z.array(text).optional(),
|
|
135
140
|
keep: z.array(text).optional(),
|
|
136
|
-
dependencies: z.array(z.string().regex(/^(?:@[a-z0-9][\w.~-]*\/)?[a-z0-9][\w.~-]*$/, { error: "must be a package name, like \"@acme/ui\"" })).refine((names) => new Set(names).size === names.length, { error: "lists a package twice" }).optional()
|
|
141
|
+
dependencies: z.array(z.string().regex(/^(?:@[a-z0-9][\w.~-]*\/)?[a-z0-9][\w.~-]*$/, { error: "must be a package name, like \"@acme/ui\"" })).refine((names) => new Set(names).size === names.length, { error: "lists a package twice" }).optional(),
|
|
142
|
+
repeatedText: z.union([z.literal(false), intIn(2, 1e3)]).optional()
|
|
137
143
|
}).optional(),
|
|
138
|
-
ids: z.strictObject({ length:
|
|
144
|
+
ids: z.strictObject({ length: intIn(ID_LENGTH.min, ID_LENGTH.max).optional() }).optional(),
|
|
139
145
|
catalogs: z.strictObject({
|
|
140
146
|
format: z.enum(["po", "json"]).optional(),
|
|
141
147
|
path: withLocale.optional(),
|
|
@@ -193,7 +199,7 @@ const configSchema = z.strictObject({
|
|
|
193
199
|
tone: z.record(z.string(), z.string()).optional(),
|
|
194
200
|
description: z.string().optional(),
|
|
195
201
|
apiKeyEnv: z.string().regex(/^[A-Za-z_]\w*$/, { error: "must be an environment variable name" }).optional(),
|
|
196
|
-
batchSize:
|
|
202
|
+
batchSize: intIn(40, 80).optional(),
|
|
197
203
|
concurrency: positiveInt.optional(),
|
|
198
204
|
dev: z.boolean().optional()
|
|
199
205
|
}).optional(),
|
|
@@ -216,6 +222,12 @@ function formatPath(path) {
|
|
|
216
222
|
else out += `[${JSON.stringify(String(key))}]`;
|
|
217
223
|
return out;
|
|
218
224
|
}
|
|
225
|
+
/** What an issue line names: the key path under `label`, the label alone, or `config` for the root. */
|
|
226
|
+
function issueSubject(label, key) {
|
|
227
|
+
if (label === "") return key || "config";
|
|
228
|
+
if (key === "") return label;
|
|
229
|
+
return `${label}${key.startsWith("[") ? "" : "."}${key}`;
|
|
230
|
+
}
|
|
219
231
|
/**
|
|
220
232
|
* One `<key path>: <problem>` line per zod issue, nested union and key
|
|
221
233
|
* issues flattened. `label` names the object the paths start from.
|
|
@@ -223,9 +235,7 @@ function formatPath(path) {
|
|
|
223
235
|
function issueLines(issues, prefix = [], label = "") {
|
|
224
236
|
const lines = [];
|
|
225
237
|
const line = (path, message) => {
|
|
226
|
-
|
|
227
|
-
const at = label === "" ? key || "config" : key === "" ? label : `${label}${key.startsWith("[") ? "" : "."}${key}`;
|
|
228
|
-
lines.push(`${at}: ${message}`);
|
|
238
|
+
lines.push(`${issueSubject(label, formatPath(path))}: ${message}`);
|
|
229
239
|
};
|
|
230
240
|
for (const issue of issues) {
|
|
231
241
|
const path = [...prefix, ...issue.path];
|
|
@@ -247,8 +257,17 @@ function issueLines(issues, prefix = [], label = "") {
|
|
|
247
257
|
}
|
|
248
258
|
return lines;
|
|
249
259
|
}
|
|
250
|
-
|
|
251
|
-
|
|
260
|
+
// src/core/config/routing.ts
|
|
261
|
+
/**
|
|
262
|
+
* `routing.paths` and `routing.domains` (PLAN §4.11, §5.14; INTERNALS §2.7.1,
|
|
263
|
+
* §6 D132, D135): the rules between their entries and the rest of the
|
|
264
|
+
* config, checked once the locale list is known, and the domain keys in the
|
|
265
|
+
* one form the runtime compares (`https://example.de`).
|
|
266
|
+
*
|
|
267
|
+
* The URL codec (`src/runtime/url.ts`) trusts what passes here: a path is
|
|
268
|
+
* either a route path or one locale's form of one, so translating it back
|
|
269
|
+
* and forth never depends on which entry is read first.
|
|
270
|
+
*/
|
|
252
271
|
/** Segments of a validated path as a pathname spells them (`*` and `**` stay). */
|
|
253
272
|
const segmentsOf = (path) => new URL(path, "http://h").pathname.split("/").slice(1);
|
|
254
273
|
/**
|
|
@@ -300,24 +319,40 @@ function domainOrigin(key) {
|
|
|
300
319
|
/** `routing.domains` with every key as `https://host[:port]` (or its `http:` origin). */
|
|
301
320
|
function resolveDomains(domains) {
|
|
302
321
|
const out = {};
|
|
303
|
-
for (const [key, locale] of Object.entries(domains))
|
|
322
|
+
for (const [key, locale] of Object.entries(domains)) {
|
|
323
|
+
const origin = domainOrigin(key);
|
|
324
|
+
if (origin === null) throw new Error(`routing.domains: ${JSON.stringify(key)} is not a host; check the config with routingProblems before resolving it`);
|
|
325
|
+
out[origin] = locale;
|
|
326
|
+
}
|
|
304
327
|
return out;
|
|
305
328
|
}
|
|
329
|
+
const at = (...keys) => formatPath(["routing", ...keys]);
|
|
306
330
|
/**
|
|
307
331
|
* Rules between `routing.paths`, `routing.domains` and the other keys. Only
|
|
308
332
|
* configured locales (never pseudo-locales, which are not advertised) may
|
|
309
333
|
* have a path or a host.
|
|
310
334
|
*/
|
|
311
335
|
function routingProblems(routing, sourceLocale, locales) {
|
|
312
|
-
const
|
|
313
|
-
const url = routing?.url ?? "prefix_except_default";
|
|
336
|
+
const url = routing?.url ?? DEFAULT_CONFIG.routing.url;
|
|
314
337
|
const paths = routing?.paths ?? {};
|
|
315
338
|
const domains = routing?.domains ?? {};
|
|
316
339
|
const hasDomains = Object.keys(domains).length > 0;
|
|
317
|
-
const
|
|
318
|
-
|
|
340
|
+
const problems = domainProblems(domains, url, locales);
|
|
341
|
+
const { valid, problems: entries } = pathEntryProblems(paths, url, locales);
|
|
342
|
+
problems.push(...entries);
|
|
343
|
+
let unprefixed = [sourceLocale];
|
|
344
|
+
if (url === "prefix" || url === "no_prefix") unprefixed = [];
|
|
345
|
+
else if (hasDomains) unprefixed = locales;
|
|
346
|
+
problems.push(...pathConflictProblems(valid, paths, locales, unprefixed));
|
|
347
|
+
return problems;
|
|
348
|
+
}
|
|
349
|
+
function domainProblems(domains, url, locales) {
|
|
350
|
+
const problems = [];
|
|
351
|
+
const hosts = Object.entries(domains);
|
|
352
|
+
if (hosts.length === 0) return problems;
|
|
353
|
+
if (url !== "prefix_except_default") problems.push(`${at("domains")}: needs routing.url "prefix_except_default" (a host's locale is its unprefixed one, every other host's prefix is redirected to that host)`);
|
|
319
354
|
const seen = /* @__PURE__ */ new Map();
|
|
320
|
-
for (const [key, locale] of
|
|
355
|
+
for (const [key, locale] of hosts) {
|
|
321
356
|
const origin = domainOrigin(key);
|
|
322
357
|
if (origin === null) {
|
|
323
358
|
problems.push(`${at("domains", key)}: must be a host such as "example.de" or an origin such as "http://localhost:5173"`);
|
|
@@ -328,63 +363,135 @@ function routingProblems(routing, sourceLocale, locales) {
|
|
|
328
363
|
seen.set(origin, key);
|
|
329
364
|
if (!locales.includes(locale)) problems.push(`${at("domains", key)}: ${JSON.stringify(locale)} is not in locales`);
|
|
330
365
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
366
|
+
const served = new Set(Object.values(domains));
|
|
367
|
+
for (const locale of locales) if (!served.has(locale)) problems.push(`${at("domains")}: no host serves ${JSON.stringify(locale)} (every locale needs one)`);
|
|
368
|
+
return problems;
|
|
369
|
+
}
|
|
370
|
+
/** Each `routing.paths` entry on its own; `valid` lists the keys whose entry has no problem. */
|
|
371
|
+
function pathEntryProblems(paths, url, locales) {
|
|
372
|
+
const problems = [];
|
|
373
|
+
if (Object.keys(paths).length > 0 && url === "no_prefix") problems.push(`${at("paths")}: needs URLs that name their locale (a routing.url other than "no_prefix")`);
|
|
337
374
|
const valid = [];
|
|
338
|
-
for (const key of
|
|
375
|
+
for (const [key, forms] of Object.entries(paths)) {
|
|
339
376
|
const problem = pathProblem(key);
|
|
340
377
|
if (problem !== null) {
|
|
341
378
|
problems.push(`${at("paths", key)}: ${problem}`);
|
|
342
379
|
continue;
|
|
343
380
|
}
|
|
344
|
-
|
|
345
|
-
for (const [locale, value] of Object.entries(
|
|
381
|
+
const before = problems.length;
|
|
382
|
+
for (const [locale, value] of Object.entries(forms)) {
|
|
346
383
|
const where = at("paths", key, locale);
|
|
347
|
-
if (!locales.includes(locale)) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}
|
|
351
|
-
const p = pathProblem(value);
|
|
352
|
-
if (p !== null) {
|
|
353
|
-
problems.push(`${where}: ${p}`);
|
|
354
|
-
ok = false;
|
|
355
|
-
} else if (wildcards(value) !== wildcards(key)) {
|
|
356
|
-
problems.push(`${where}: must keep the wildcards of ${JSON.stringify(key)}, in order`);
|
|
357
|
-
ok = false;
|
|
358
|
-
}
|
|
384
|
+
if (!locales.includes(locale)) problems.push(`${where}: ${JSON.stringify(locale)} is not in locales`);
|
|
385
|
+
const valueProblem = pathProblem(value);
|
|
386
|
+
if (valueProblem !== null) problems.push(`${where}: ${valueProblem}`);
|
|
387
|
+
else if (wildcards(value) !== wildcards(key)) problems.push(`${where}: must keep the wildcards of ${JSON.stringify(key)}, in order`);
|
|
359
388
|
}
|
|
360
|
-
if (
|
|
389
|
+
if (problems.length === before) valid.push(key);
|
|
361
390
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
391
|
+
return {
|
|
392
|
+
valid,
|
|
393
|
+
problems
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Pairs of valid routes whose forms in one locale are the same path, or
|
|
398
|
+
* overlap where the route paths do not; and, where a locale is unprefixed,
|
|
399
|
+
* a translated path that would read as another route's path.
|
|
400
|
+
*/
|
|
401
|
+
function pathConflictProblems(valid, paths, locales, unprefixed) {
|
|
402
|
+
const problems = [];
|
|
403
|
+
const formOf = (route, locale) => Object.hasOwn(paths[route], locale) ? paths[route][locale] : route;
|
|
404
|
+
const segmentsCache = new Map(valid.map((route) => [route, segmentsOf(route)]));
|
|
405
|
+
const segments = (path) => segmentsCache.get(path) ?? segmentsOf(path);
|
|
406
|
+
for (const locale of locales) {
|
|
367
407
|
for (let i = 0; i < valid.length; i++) {
|
|
368
|
-
const
|
|
369
|
-
const
|
|
408
|
+
const routeA = valid[i];
|
|
409
|
+
const formA = formOf(routeA, locale);
|
|
370
410
|
for (let j = i + 1; j < valid.length; j++) {
|
|
371
|
-
const
|
|
372
|
-
const
|
|
373
|
-
const where = at("paths", Object.hasOwn(paths[
|
|
374
|
-
if (
|
|
375
|
-
else if (overlap(
|
|
411
|
+
const routeB = valid[j];
|
|
412
|
+
const formB = formOf(routeB, locale);
|
|
413
|
+
const where = at("paths", Object.hasOwn(paths[routeB], locale) ? routeB : routeA, locale);
|
|
414
|
+
if (formA === formB) problems.push(`${where}: ${JSON.stringify(routeA)} and ${JSON.stringify(routeB)} share the path ${JSON.stringify(formA)} in ${locale}`);
|
|
415
|
+
else if (overlap(segments(formA), segments(formB)) && !overlap(segments(routeA), segments(routeB))) problems.push(`${where}: ${JSON.stringify(formA)} and ${JSON.stringify(formB)} overlap in ${locale}, but ${JSON.stringify(routeA)} and ${JSON.stringify(routeB)} do not`);
|
|
376
416
|
}
|
|
377
417
|
}
|
|
378
|
-
if (
|
|
379
|
-
for (const a of valid) for (const b of valid) {
|
|
380
|
-
if (a === b || !Object.hasOwn(paths[b], l)) continue;
|
|
381
|
-
if (overlap(segOf(a), segOf(paths[b][l]))) problems.push(`${at("paths", b, l)}: ${JSON.stringify(paths[b][l])} would read as the route ${JSON.stringify(a)} where ${l} is unprefixed`);
|
|
382
|
-
}
|
|
418
|
+
if (unprefixed.includes(locale)) problems.push(...unprefixedProblems(valid, paths, locale, segments));
|
|
383
419
|
}
|
|
384
420
|
return problems;
|
|
385
421
|
}
|
|
386
|
-
|
|
387
|
-
|
|
422
|
+
/** Where `locale` is unprefixed, a translated path must not read as another route's path. */
|
|
423
|
+
function unprefixedProblems(valid, paths, locale, segments) {
|
|
424
|
+
const problems = [];
|
|
425
|
+
for (const routeA of valid) for (const routeB of valid) {
|
|
426
|
+
if (routeA === routeB || !Object.hasOwn(paths[routeB], locale)) continue;
|
|
427
|
+
if (overlap(segments(routeA), segments(paths[routeB][locale]))) problems.push(`${at("paths", routeB, locale)}: ${JSON.stringify(paths[routeB][locale])} would read as the route ${JSON.stringify(routeA)} where ${locale} is unprefixed`);
|
|
428
|
+
}
|
|
429
|
+
return problems;
|
|
430
|
+
}
|
|
431
|
+
// src/core/config/runtime.ts
|
|
432
|
+
/**
|
|
433
|
+
* Pseudo-locales are a development aid: on in `vite dev` and non-production
|
|
434
|
+
* builds (previews, staging), off in production and for the CLI unless
|
|
435
|
+
* `vi18n compile --pseudo` asks for them.
|
|
436
|
+
*/
|
|
437
|
+
function pseudoActive(command, mode) {
|
|
438
|
+
if (command === "serve") return true;
|
|
439
|
+
if (command === "build") return mode !== "production";
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
function toRuntimeConfig(config, options) {
|
|
443
|
+
const pseudoLocales = options.pseudo ? [...config.pseudoLocales] : [];
|
|
444
|
+
const { routing, ssr } = config;
|
|
445
|
+
return {
|
|
446
|
+
sourceLocale: config.sourceLocale,
|
|
447
|
+
locales: [...config.locales, ...pseudoLocales],
|
|
448
|
+
pseudoLocales,
|
|
449
|
+
fallbacks: mapRecord(config.fallbacks, (chain) => [...chain]),
|
|
450
|
+
routing: {
|
|
451
|
+
strategy: [...routing.strategy],
|
|
452
|
+
routeStrategies: mapRecord(routing.routeStrategies, (chain) => [...chain]),
|
|
453
|
+
url: routing.url,
|
|
454
|
+
redirectRoot: routing.redirectRoot,
|
|
455
|
+
propagate: routing.propagate,
|
|
456
|
+
switch: routing.switch,
|
|
457
|
+
cookie: {
|
|
458
|
+
name: routing.cookie.name,
|
|
459
|
+
maxAge: routing.cookie.maxAge
|
|
460
|
+
},
|
|
461
|
+
base: normalizeBase(routing.base ?? options.base),
|
|
462
|
+
...Object.keys(routing.paths).length > 0 && { paths: mapRecord(routing.paths, (entry) => ({ ...entry })) },
|
|
463
|
+
...Object.keys(routing.domains).length > 0 && { domains: mapRecord(routing.domains, (locale) => locale) }
|
|
464
|
+
},
|
|
465
|
+
ssr: {
|
|
466
|
+
timeZone: ssr.timeZone,
|
|
467
|
+
timeZoneFrom: mapRecord(ssr.timeZoneFrom, (source) => source),
|
|
468
|
+
normalizeSpaces: ssr.normalizeSpaces,
|
|
469
|
+
...ssr.payload === "preload" && { payload: "preload" }
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
/** Whether the config localizes paths or routes by domain: the plugin's `__VI18N_ROUTES__`. */
|
|
474
|
+
function hasRoutes(config) {
|
|
475
|
+
return Object.keys(config.routing.paths).length > 0 || Object.keys(config.routing.domains).length > 0;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Vite's `base` as the URL codec needs it: a pathname starting and ending
|
|
479
|
+
* with `/`. A relative base (`""`, `./`) serves the app from wherever it is
|
|
480
|
+
* mounted, which for locale prefixes means the root; a full URL (CDN base)
|
|
481
|
+
* contributes its pathname.
|
|
482
|
+
*/
|
|
483
|
+
function normalizeBase(base) {
|
|
484
|
+
let path = base;
|
|
485
|
+
if (/^[a-z][a-z\d+.-]*:\/\//i.test(path) || path.startsWith("//")) path = new URL(path, "http://localhost").pathname;
|
|
486
|
+
if (path === "" || path === "." || path === "./") return "/";
|
|
487
|
+
if (!path.startsWith("/")) path = "/" + path.replace(/^\.\//, "");
|
|
488
|
+
return path.endsWith("/") ? path : path + "/";
|
|
489
|
+
}
|
|
490
|
+
/** A fresh record of mapped values; `fromEntries` defines properties, so a `__proto__` key stays a key. */
|
|
491
|
+
function mapRecord(record, map) {
|
|
492
|
+
return Object.fromEntries(Object.entries(record).map(([key, value]) => [key, map(value)]));
|
|
493
|
+
}
|
|
494
|
+
// src/core/config/load.ts
|
|
388
495
|
/**
|
|
389
496
|
* Finding, loading and resolving `vi18n.config.ts` (PLAN §5.7, INTERNALS
|
|
390
497
|
* §2.7.1, spike S8). The plugin and the CLI both come through `loadConfig`,
|
|
@@ -578,7 +685,7 @@ function resolveConfig(input, root, configFile) {
|
|
|
578
685
|
}
|
|
579
686
|
function resolveWith(input, root, configFile, inline) {
|
|
580
687
|
root = resolve(root);
|
|
581
|
-
const file = configFile === null ? void 0 :
|
|
688
|
+
const file = configFile === null ? void 0 : displayPath(root, resolve(configFile));
|
|
582
689
|
const result = configSchema.safeParse(input);
|
|
583
690
|
if (!result.success) throw invalid(file, issueLines(result.error.issues).join("; "));
|
|
584
691
|
const user = inline === void 0 ? result.data : {
|
|
@@ -590,73 +697,22 @@ function resolveWith(input, root, configFile, inline) {
|
|
|
590
697
|
const problems = crossFieldProblems(user, sourceLocale, locales);
|
|
591
698
|
if (problems.length > 0) throw invalid(file, problems.join("; "));
|
|
592
699
|
const d = DEFAULT_CONFIG;
|
|
593
|
-
const format = user.catalogs?.format ?? d.catalogs.format;
|
|
594
|
-
const catalogPath = user.catalogs?.path ?? (format === "json" ? JSON_CATALOG_PATH : d.catalogs.path);
|
|
595
|
-
const provider = user.ai?.provider ?? d.ai.provider;
|
|
596
700
|
return {
|
|
597
701
|
root,
|
|
598
702
|
configFile: configFile === null ? null : resolve(configFile),
|
|
599
703
|
sourceLocale,
|
|
600
704
|
locales,
|
|
601
705
|
pseudoLocales: [...new Set(user.pseudoLocales ?? d.pseudoLocales)],
|
|
602
|
-
fallbacks:
|
|
603
|
-
project:
|
|
604
|
-
|
|
605
|
-
extensions: [...user.project?.extensions ?? d.project.extensions],
|
|
606
|
-
exclude: [...user.project?.exclude ?? d.project.exclude]
|
|
607
|
-
},
|
|
608
|
-
extraction: {
|
|
609
|
-
importSources: [.../* @__PURE__ */ new Set([...DEFAULT_IMPORT_SOURCES, ...user.extraction?.importSources ?? []])],
|
|
610
|
-
aliases: [...user.extraction?.aliases ?? d.extraction.aliases],
|
|
611
|
-
globals: [...user.extraction?.globals ?? d.extraction.globals],
|
|
612
|
-
keep: [...user.extraction?.keep ?? d.extraction.keep],
|
|
613
|
-
dependencies: [...user.extraction?.dependencies ?? d.extraction.dependencies]
|
|
614
|
-
},
|
|
706
|
+
fallbacks: mapRecord(user.fallbacks ?? d.fallbacks, (chain) => [...chain]),
|
|
707
|
+
project: resolveProject(user.project, root),
|
|
708
|
+
extraction: resolveExtraction(user.extraction),
|
|
615
709
|
ids: { length: user.ids?.length ?? d.ids.length },
|
|
616
|
-
catalogs:
|
|
617
|
-
format,
|
|
618
|
-
path: resolve(root, catalogPath),
|
|
619
|
-
msgid: user.catalogs?.msgid ?? d.catalogs.msgid,
|
|
620
|
-
icuFlag: user.catalogs?.icuFlag ?? d.catalogs.icuFlag
|
|
621
|
-
},
|
|
710
|
+
catalogs: resolveCatalogs(user.catalogs, root),
|
|
622
711
|
output: resolveOutput(user.output),
|
|
623
|
-
routing:
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
redirectRoot: user.routing?.redirectRoot ?? d.routing.redirectRoot,
|
|
628
|
-
propagate: user.routing?.propagate ?? d.routing.propagate,
|
|
629
|
-
switch: user.routing?.switch ?? d.routing.switch,
|
|
630
|
-
cookie: {
|
|
631
|
-
name: user.routing?.cookie?.name ?? d.routing.cookie.name,
|
|
632
|
-
maxAge: user.routing?.cookie?.maxAge ?? d.routing.cookie.maxAge
|
|
633
|
-
},
|
|
634
|
-
base: user.routing?.base ?? d.routing.base,
|
|
635
|
-
paths: copyRecord(user.routing?.paths ?? d.routing.paths, (entry) => ({ ...entry })),
|
|
636
|
-
domains: resolveDomains(user.routing?.domains ?? d.routing.domains)
|
|
637
|
-
},
|
|
638
|
-
ssr: {
|
|
639
|
-
timeZone: user.ssr?.timeZone ?? d.ssr.timeZone,
|
|
640
|
-
timeZoneFrom: copyRecord(user.ssr?.timeZoneFrom ?? d.ssr.timeZoneFrom, (v) => v),
|
|
641
|
-
payload: user.ssr?.payload ?? d.ssr.payload,
|
|
642
|
-
catalogs: user.ssr?.catalogs ?? d.ssr.catalogs,
|
|
643
|
-
maxLoadedLocales: user.ssr?.maxLoadedLocales ?? d.ssr.maxLoadedLocales,
|
|
644
|
-
normalizeSpaces: user.ssr?.normalizeSpaces ?? d.ssr.normalizeSpaces
|
|
645
|
-
},
|
|
646
|
-
ai: {
|
|
647
|
-
provider,
|
|
648
|
-
model: user.ai?.model ?? (typeof provider === "string" ? d.ai.model : provider.model),
|
|
649
|
-
exclude: [...user.ai?.exclude ?? d.ai.exclude],
|
|
650
|
-
glossary: copyRecord(user.ai?.glossary ?? d.ai.glossary, (targets) => copyRecord(targets, (v) => v)),
|
|
651
|
-
doNotTranslate: [...user.ai?.doNotTranslate ?? d.ai.doNotTranslate],
|
|
652
|
-
tone: copyRecord(user.ai?.tone ?? d.ai.tone, (v) => v),
|
|
653
|
-
description: user.ai?.description ?? d.ai.description,
|
|
654
|
-
apiKeyEnv: user.ai?.apiKeyEnv ?? d.ai.apiKeyEnv,
|
|
655
|
-
batchSize: user.ai?.batchSize ?? d.ai.batchSize,
|
|
656
|
-
concurrency: user.ai?.concurrency ?? d.ai.concurrency,
|
|
657
|
-
dev: user.ai?.dev ?? d.ai.dev
|
|
658
|
-
},
|
|
659
|
-
defaults: { tags: copyRecord(user.defaults?.tags ?? d.defaults.tags, (spec) => typeof spec === "string" ? spec : {
|
|
712
|
+
routing: resolveRouting(user.routing),
|
|
713
|
+
ssr: resolveSsr(user.ssr),
|
|
714
|
+
ai: resolveAi(user.ai),
|
|
715
|
+
defaults: { tags: mapRecord(user.defaults?.tags ?? d.defaults.tags, (spec) => typeof spec === "string" ? spec : {
|
|
660
716
|
element: spec.element,
|
|
661
717
|
attributes: { ...spec.attributes }
|
|
662
718
|
}) },
|
|
@@ -664,6 +720,88 @@ function resolveWith(input, root, configFile, inline) {
|
|
|
664
720
|
strict: resolveStrict(user.strict)
|
|
665
721
|
};
|
|
666
722
|
}
|
|
723
|
+
function resolveProject(given, root) {
|
|
724
|
+
const d = DEFAULT_CONFIG.project;
|
|
725
|
+
const user = given ?? {};
|
|
726
|
+
return {
|
|
727
|
+
include: (user.include ?? d.include).map((entry) => resolve(root, entry)),
|
|
728
|
+
extensions: [...user.extensions ?? d.extensions],
|
|
729
|
+
exclude: [...user.exclude ?? d.exclude]
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
function resolveExtraction(given) {
|
|
733
|
+
const d = DEFAULT_CONFIG.extraction;
|
|
734
|
+
const user = given ?? {};
|
|
735
|
+
return {
|
|
736
|
+
importSources: [.../* @__PURE__ */ new Set([...DEFAULT_IMPORT_SOURCES, ...user.importSources ?? []])],
|
|
737
|
+
aliases: [...user.aliases ?? d.aliases],
|
|
738
|
+
globals: [...user.globals ?? d.globals],
|
|
739
|
+
keep: [...user.keep ?? d.keep],
|
|
740
|
+
dependencies: [...user.dependencies ?? d.dependencies],
|
|
741
|
+
repeatedText: user.repeatedText ?? d.repeatedText
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
function resolveCatalogs(given, root) {
|
|
745
|
+
const d = DEFAULT_CONFIG.catalogs;
|
|
746
|
+
const user = given ?? {};
|
|
747
|
+
const format = user.format ?? d.format;
|
|
748
|
+
const path = user.path ?? (format === "json" ? JSON_CATALOG_PATH : d.path);
|
|
749
|
+
return {
|
|
750
|
+
format,
|
|
751
|
+
path: resolve(root, path),
|
|
752
|
+
msgid: user.msgid ?? d.msgid,
|
|
753
|
+
icuFlag: user.icuFlag ?? d.icuFlag
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
function resolveRouting(given) {
|
|
757
|
+
const d = DEFAULT_CONFIG.routing;
|
|
758
|
+
const user = given ?? {};
|
|
759
|
+
return {
|
|
760
|
+
strategy: [...user.strategy ?? d.strategy],
|
|
761
|
+
routeStrategies: mapRecord(user.routeStrategies ?? d.routeStrategies, (chain) => [...chain]),
|
|
762
|
+
url: user.url ?? d.url,
|
|
763
|
+
redirectRoot: user.redirectRoot ?? d.redirectRoot,
|
|
764
|
+
propagate: user.propagate ?? d.propagate,
|
|
765
|
+
switch: user.switch ?? d.switch,
|
|
766
|
+
cookie: {
|
|
767
|
+
name: user.cookie?.name ?? d.cookie.name,
|
|
768
|
+
maxAge: user.cookie?.maxAge ?? d.cookie.maxAge
|
|
769
|
+
},
|
|
770
|
+
base: user.base ?? d.base,
|
|
771
|
+
paths: mapRecord(user.paths ?? d.paths, (entry) => ({ ...entry })),
|
|
772
|
+
domains: resolveDomains(user.domains ?? d.domains)
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
function resolveSsr(given) {
|
|
776
|
+
const d = DEFAULT_CONFIG.ssr;
|
|
777
|
+
const user = given ?? {};
|
|
778
|
+
return {
|
|
779
|
+
timeZone: user.timeZone ?? d.timeZone,
|
|
780
|
+
timeZoneFrom: mapRecord(user.timeZoneFrom ?? d.timeZoneFrom, (v) => v),
|
|
781
|
+
payload: user.payload ?? d.payload,
|
|
782
|
+
catalogs: user.catalogs ?? d.catalogs,
|
|
783
|
+
maxLoadedLocales: user.maxLoadedLocales ?? d.maxLoadedLocales,
|
|
784
|
+
normalizeSpaces: user.normalizeSpaces ?? d.normalizeSpaces
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
function resolveAi(given) {
|
|
788
|
+
const d = DEFAULT_CONFIG.ai;
|
|
789
|
+
const user = given ?? {};
|
|
790
|
+
const provider = user.provider ?? d.provider;
|
|
791
|
+
return {
|
|
792
|
+
provider,
|
|
793
|
+
model: user.model ?? (typeof provider === "string" ? d.model : provider.model),
|
|
794
|
+
exclude: [...user.exclude ?? d.exclude],
|
|
795
|
+
glossary: mapRecord(user.glossary ?? d.glossary, (targets) => mapRecord(targets, (v) => v)),
|
|
796
|
+
doNotTranslate: [...user.doNotTranslate ?? d.doNotTranslate],
|
|
797
|
+
tone: mapRecord(user.tone ?? d.tone, (v) => v),
|
|
798
|
+
description: user.description ?? d.description,
|
|
799
|
+
apiKeyEnv: user.apiKeyEnv ?? d.apiKeyEnv,
|
|
800
|
+
batchSize: user.batchSize ?? d.batchSize,
|
|
801
|
+
concurrency: user.concurrency ?? d.concurrency,
|
|
802
|
+
dev: user.dev ?? d.dev
|
|
803
|
+
};
|
|
804
|
+
}
|
|
667
805
|
/** Rules between keys, checked once the locale list is known. */
|
|
668
806
|
function crossFieldProblems(user, sourceLocale, locales) {
|
|
669
807
|
const problems = [];
|
|
@@ -700,12 +838,7 @@ function crossFieldProblems(user, sourceLocale, locales) {
|
|
|
700
838
|
function resolveOutput(user) {
|
|
701
839
|
const d = DEFAULT_CONFIG.output;
|
|
702
840
|
return {
|
|
703
|
-
split:
|
|
704
|
-
shared: user?.split?.shared ?? d.split.shared,
|
|
705
|
-
dupBelow: user?.split?.dupBelow ?? d.split.dupBelow,
|
|
706
|
-
minBytes: user?.split?.minBytes ?? d.split.minBytes,
|
|
707
|
-
maxBundlesPerRoot: user?.split?.maxBundlesPerRoot === void 0 ? d.split.maxBundlesPerRoot : user.split.maxBundlesPerRoot
|
|
708
|
-
},
|
|
841
|
+
split: resolveSplit(user?.split),
|
|
709
842
|
guard: user?.guard ?? d.guard,
|
|
710
843
|
manifestPath: user?.manifestPath ?? d.manifestPath,
|
|
711
844
|
manifest: user?.manifest ?? d.manifest,
|
|
@@ -714,6 +847,16 @@ function resolveOutput(user) {
|
|
|
714
847
|
perLocale: user?.perLocale ?? d.perLocale
|
|
715
848
|
};
|
|
716
849
|
}
|
|
850
|
+
function resolveSplit(given) {
|
|
851
|
+
const d = DEFAULT_CONFIG.output.split;
|
|
852
|
+
const user = given ?? {};
|
|
853
|
+
return {
|
|
854
|
+
shared: user.shared ?? d.shared,
|
|
855
|
+
dupBelow: user.dupBelow ?? d.dupBelow,
|
|
856
|
+
minBytes: user.minBytes ?? d.minBytes,
|
|
857
|
+
maxBundlesPerRoot: user.maxBundlesPerRoot === void 0 ? d.maxBundlesPerRoot : user.maxBundlesPerRoot
|
|
858
|
+
};
|
|
859
|
+
}
|
|
717
860
|
function resolveStrict(strict) {
|
|
718
861
|
const d = DEFAULT_CONFIG.strict;
|
|
719
862
|
if (strict === true) return {
|
|
@@ -722,26 +865,10 @@ function resolveStrict(strict) {
|
|
|
722
865
|
moduleScope: "error"
|
|
723
866
|
};
|
|
724
867
|
if (strict === void 0 || strict === false) return { ...d };
|
|
725
|
-
const pick = (value, fallback) => value ?? fallback;
|
|
726
868
|
return {
|
|
727
|
-
missing:
|
|
728
|
-
invalid:
|
|
729
|
-
moduleScope:
|
|
869
|
+
missing: strict.missing ?? d.missing,
|
|
870
|
+
invalid: strict.invalid ?? d.invalid,
|
|
871
|
+
moduleScope: strict.moduleScope ?? d.moduleScope
|
|
730
872
|
};
|
|
731
873
|
}
|
|
732
|
-
|
|
733
|
-
* A fresh copy, so resolved configs never share arrays with the input or the
|
|
734
|
-
* defaults. `fromEntries` defines properties, so a `__proto__` key stays a key.
|
|
735
|
-
*/
|
|
736
|
-
function copyRecord(record, copy) {
|
|
737
|
-
return Object.fromEntries(Object.entries(record).map(([key, value]) => [key, copy(value)]));
|
|
738
|
-
}
|
|
739
|
-
function relativeOrAbsolute(root, file) {
|
|
740
|
-
const rel = relative(root, resolve(file));
|
|
741
|
-
return rel === "" || rel.startsWith("..") || isAbsolute(rel) ? resolve(file) : rel;
|
|
742
|
-
}
|
|
743
|
-
function toPosix(path) {
|
|
744
|
-
return sep === "/" ? path : path.split(sep).join("/");
|
|
745
|
-
}
|
|
746
|
-
//#endregion
|
|
747
|
-
export { loadConfig as n, resolveConfig as r, findConfigFile as t };
|
|
874
|
+
export { hasRoutes as a, toRuntimeConfig as c, resolveConfig as i, isWorkspaceRoot as n, normalizeBase as o, loadConfig as r, pseudoActive as s, findConfigFile as t };
|