@menapo/vi18n 0.1.1 → 0.1.2
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/dist/{apply-Bre-lY9J.js → apply-FAHl1R6T.js} +69 -89
- package/dist/{captured-Bj8bO6vd.js → captured-CTjjDF5o.js} +196 -217
- package/dist/{check-BIKEuu6B.js → check-DwFwOB1d.js} +66 -84
- package/dist/cli.js +2 -3
- package/dist/{collect-Cx4_SKOe.js → collect-CYATDjdo.js} +1 -2
- package/dist/collisions-uMTuq36M.js +215 -0
- package/dist/compile-CEvH-6sY.js +240 -0
- package/dist/{compile-Cc97JaW2.js → compile-DqkofbiO.js} +376 -331
- 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-1onDF6Ua.js} +26 -26
- package/dist/{dir-zw6bGMKQ.js → dir-TGLYuOZb.js} +34 -37
- package/dist/{duplicates-yuRljQ6h.js → duplicates-CsUXRX2J.js} +10 -27
- package/dist/engine-Bf7nVigL.js +556 -0
- package/dist/engine.d.ts +1 -5
- package/dist/engine.js +297 -168
- package/dist/exchange-DYG9RZoT.js +41 -0
- package/dist/{exclude-Du-Zd_qI.js → exclude-vMnm3lqU.js} +2 -3
- package/dist/{export-C9Sy6UWv.js → export-BYq0gfLd.js} +17 -38
- package/dist/{extract-C3S8btx0.js → extract-CYtuEo8u.js} +114 -82
- package/dist/{formats-9unqj_fZ.js → formats-ChV1LVH_.js} +352 -276
- package/dist/fs-ezCMZeDV.js +52 -0
- package/dist/i18next-1waHziMy.js +1 -0
- package/dist/i18next-D66Icz3L.js +1907 -0
- package/dist/{import-nANvQutw.js → import-BApbQlmm.js} +81 -75
- package/dist/index.d.ts +1 -13
- package/dist/index.js +14 -16
- package/dist/{init-C2ScuW6a.js → init-J7AwwA5e.js} +466 -501
- package/dist/{library-D5CWvTQs.js → library-BfSOBeBd.js} +975 -451
- package/dist/lingui-Ee2farVo.js +902 -0
- package/dist/lint.d.ts +0 -4
- package/dist/lint.js +68 -81
- package/dist/{load-gW-oJt1Q.js → load-BFLLqY8x.js} +272 -147
- package/dist/{load-CQRz4PpM.js → load-CMwhukZ4.js} +1211 -1115
- package/dist/{locales-DX4MOBFE.js → locales-DxLDrx-h.js} +271 -237
- package/dist/{lsp-RMMMc88P.js → lsp-BC7xDGON.js} +4 -5
- package/dist/{match-BGr8EXB3.js → match-BLDcj610.js} +11 -4
- package/dist/{mcp-CHVwBoRP.js → mcp-Cka8ywDF.js} +4 -5
- package/dist/{merge-driver-BTX87aVm.js → merge-driver-B04Apm29.js} +138 -122
- package/dist/migrate-D7TNl6SD.js +2169 -0
- package/dist/migrate-khCY8TE0.js +1 -0
- package/dist/{openai-CTaMDcl-.js → openai-RWw0YlAx.js} +128 -87
- package/dist/{output-DWE3SIUA.js → output-CF9uvk_-.js} +15 -9
- package/dist/parse.d.ts +1 -3
- package/dist/parse.js +7 -8
- package/dist/{pipeline-DbX6rlo5.js → pipeline-B30irGMD.js} +1 -1
- package/dist/{pipeline-C9Dbotkh.js → pipeline-sgl_q_op.js} +387 -359
- package/dist/project-DSzWKU3C.js +544 -0
- package/dist/{pseudo-DRv30iN5.js → pseudo-DNbNNVGP.js} +125 -3
- package/dist/{raw-C4Y6vyGY.js → raw-YsYZMS9n.js} +52 -29
- package/dist/react-intl-tzGIk6G3.js +634 -0
- package/dist/restore-BG_zMpSj.js +199 -0
- package/dist/rewrite-hAcRJwiZ.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-CFzR3V93.js +647 -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-deBOq2vq.js → server-WlxZH0oX.js} +275 -330
- package/dist/{server-Da1Ot9IN.js → server-ceuzzkal.js} +292 -386
- package/dist/server.d.ts +1 -17
- package/dist/server.js +415 -381
- package/dist/{sitemap-DJXzKoza.js → sitemap-796jJKUT.js} +21 -33
- package/dist/{sources-D19czDSA.js → sources-DuOdM02f.js} +712 -373
- package/dist/{status-zr4jY59Y.js → status-CTH3qI-0.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-CpL0Qsgw.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 +77 -48
- package/dist/translate-BrfVRkjl.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-BaG1LboH.d.ts} +2 -6
- package/dist/{types-CgUCkFU1.d.ts → types-Cy2bPdSg.d.ts} +14 -20
- package/dist/types-Ds_vebja.js +41 -0
- package/dist/{units-CQ5Q99RC.js → units-VVLgQ7x7.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-D6DJepZv.js → validate-PGgMsasz.js} +3 -5
- package/dist/{validate-BxpupdAf.js → validate-zv4-IZyZ.js} +690 -377
- package/dist/{version-Byqi2guX.js → version-BFs370Ce.js} +3 -5
- package/dist/{vite-scan-CT_vsp4g.js → vite-scan-DFKSGVE9.js} +87 -92
- package/dist/vite.d.ts +2 -6
- package/dist/vite.js +6482 -6018
- package/dist/vue-i18n-CBmZqHbG.js +806 -0
- package/dist/{which-BOemZ5Q8.js → which-BpyJyBkX.js} +44 -37
- package/dist/{worker-84U6uYB3.js → worker-BjzVqJVO.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-1onDF6Ua.js";
|
|
2
|
+
import { u as toPosix } from "./validate-zv4-IZyZ.js";
|
|
3
|
+
import { P as displayPath } from "./library-BfSOBeBd.js";
|
|
4
|
+
import { t as excludeKind } from "./exclude-vMnm3lqU.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(),
|
|
@@ -135,7 +140,7 @@ const configSchema = z.strictObject({
|
|
|
135
140
|
keep: z.array(text).optional(),
|
|
136
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()
|
|
137
142
|
}).optional(),
|
|
138
|
-
ids: z.strictObject({ length:
|
|
143
|
+
ids: z.strictObject({ length: intIn(ID_LENGTH.min, ID_LENGTH.max).optional() }).optional(),
|
|
139
144
|
catalogs: z.strictObject({
|
|
140
145
|
format: z.enum(["po", "json"]).optional(),
|
|
141
146
|
path: withLocale.optional(),
|
|
@@ -193,7 +198,7 @@ const configSchema = z.strictObject({
|
|
|
193
198
|
tone: z.record(z.string(), z.string()).optional(),
|
|
194
199
|
description: z.string().optional(),
|
|
195
200
|
apiKeyEnv: z.string().regex(/^[A-Za-z_]\w*$/, { error: "must be an environment variable name" }).optional(),
|
|
196
|
-
batchSize:
|
|
201
|
+
batchSize: intIn(40, 80).optional(),
|
|
197
202
|
concurrency: positiveInt.optional(),
|
|
198
203
|
dev: z.boolean().optional()
|
|
199
204
|
}).optional(),
|
|
@@ -216,6 +221,12 @@ function formatPath(path) {
|
|
|
216
221
|
else out += `[${JSON.stringify(String(key))}]`;
|
|
217
222
|
return out;
|
|
218
223
|
}
|
|
224
|
+
/** What an issue line names: the key path under `label`, the label alone, or `config` for the root. */
|
|
225
|
+
function issueSubject(label, key) {
|
|
226
|
+
if (label === "") return key || "config";
|
|
227
|
+
if (key === "") return label;
|
|
228
|
+
return `${label}${key.startsWith("[") ? "" : "."}${key}`;
|
|
229
|
+
}
|
|
219
230
|
/**
|
|
220
231
|
* One `<key path>: <problem>` line per zod issue, nested union and key
|
|
221
232
|
* issues flattened. `label` names the object the paths start from.
|
|
@@ -223,9 +234,7 @@ function formatPath(path) {
|
|
|
223
234
|
function issueLines(issues, prefix = [], label = "") {
|
|
224
235
|
const lines = [];
|
|
225
236
|
const line = (path, message) => {
|
|
226
|
-
|
|
227
|
-
const at = label === "" ? key || "config" : key === "" ? label : `${label}${key.startsWith("[") ? "" : "."}${key}`;
|
|
228
|
-
lines.push(`${at}: ${message}`);
|
|
237
|
+
lines.push(`${issueSubject(label, formatPath(path))}: ${message}`);
|
|
229
238
|
};
|
|
230
239
|
for (const issue of issues) {
|
|
231
240
|
const path = [...prefix, ...issue.path];
|
|
@@ -247,8 +256,17 @@ function issueLines(issues, prefix = [], label = "") {
|
|
|
247
256
|
}
|
|
248
257
|
return lines;
|
|
249
258
|
}
|
|
250
|
-
|
|
251
|
-
|
|
259
|
+
// src/core/config/routing.ts
|
|
260
|
+
/**
|
|
261
|
+
* `routing.paths` and `routing.domains` (PLAN §4.11, §5.14; INTERNALS §2.7.1,
|
|
262
|
+
* §6 D132, D135): the rules between their entries and the rest of the
|
|
263
|
+
* config, checked once the locale list is known, and the domain keys in the
|
|
264
|
+
* one form the runtime compares (`https://example.de`).
|
|
265
|
+
*
|
|
266
|
+
* The URL codec (`src/runtime/url.ts`) trusts what passes here: a path is
|
|
267
|
+
* either a route path or one locale's form of one, so translating it back
|
|
268
|
+
* and forth never depends on which entry is read first.
|
|
269
|
+
*/
|
|
252
270
|
/** Segments of a validated path as a pathname spells them (`*` and `**` stay). */
|
|
253
271
|
const segmentsOf = (path) => new URL(path, "http://h").pathname.split("/").slice(1);
|
|
254
272
|
/**
|
|
@@ -300,24 +318,40 @@ function domainOrigin(key) {
|
|
|
300
318
|
/** `routing.domains` with every key as `https://host[:port]` (or its `http:` origin). */
|
|
301
319
|
function resolveDomains(domains) {
|
|
302
320
|
const out = {};
|
|
303
|
-
for (const [key, locale] of Object.entries(domains))
|
|
321
|
+
for (const [key, locale] of Object.entries(domains)) {
|
|
322
|
+
const origin = domainOrigin(key);
|
|
323
|
+
if (origin === null) throw new Error(`routing.domains: ${JSON.stringify(key)} is not a host; check the config with routingProblems before resolving it`);
|
|
324
|
+
out[origin] = locale;
|
|
325
|
+
}
|
|
304
326
|
return out;
|
|
305
327
|
}
|
|
328
|
+
const at = (...keys) => formatPath(["routing", ...keys]);
|
|
306
329
|
/**
|
|
307
330
|
* Rules between `routing.paths`, `routing.domains` and the other keys. Only
|
|
308
331
|
* configured locales (never pseudo-locales, which are not advertised) may
|
|
309
332
|
* have a path or a host.
|
|
310
333
|
*/
|
|
311
334
|
function routingProblems(routing, sourceLocale, locales) {
|
|
312
|
-
const
|
|
313
|
-
const url = routing?.url ?? "prefix_except_default";
|
|
335
|
+
const url = routing?.url ?? DEFAULT_CONFIG.routing.url;
|
|
314
336
|
const paths = routing?.paths ?? {};
|
|
315
337
|
const domains = routing?.domains ?? {};
|
|
316
338
|
const hasDomains = Object.keys(domains).length > 0;
|
|
317
|
-
const
|
|
318
|
-
|
|
339
|
+
const problems = domainProblems(domains, url, locales);
|
|
340
|
+
const { valid, problems: entries } = pathEntryProblems(paths, url, locales);
|
|
341
|
+
problems.push(...entries);
|
|
342
|
+
let unprefixed = [sourceLocale];
|
|
343
|
+
if (url === "prefix" || url === "no_prefix") unprefixed = [];
|
|
344
|
+
else if (hasDomains) unprefixed = locales;
|
|
345
|
+
problems.push(...pathConflictProblems(valid, paths, locales, unprefixed));
|
|
346
|
+
return problems;
|
|
347
|
+
}
|
|
348
|
+
function domainProblems(domains, url, locales) {
|
|
349
|
+
const problems = [];
|
|
350
|
+
const hosts = Object.entries(domains);
|
|
351
|
+
if (hosts.length === 0) return problems;
|
|
352
|
+
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
353
|
const seen = /* @__PURE__ */ new Map();
|
|
320
|
-
for (const [key, locale] of
|
|
354
|
+
for (const [key, locale] of hosts) {
|
|
321
355
|
const origin = domainOrigin(key);
|
|
322
356
|
if (origin === null) {
|
|
323
357
|
problems.push(`${at("domains", key)}: must be a host such as "example.de" or an origin such as "http://localhost:5173"`);
|
|
@@ -328,63 +362,135 @@ function routingProblems(routing, sourceLocale, locales) {
|
|
|
328
362
|
seen.set(origin, key);
|
|
329
363
|
if (!locales.includes(locale)) problems.push(`${at("domains", key)}: ${JSON.stringify(locale)} is not in locales`);
|
|
330
364
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
365
|
+
const served = new Set(Object.values(domains));
|
|
366
|
+
for (const locale of locales) if (!served.has(locale)) problems.push(`${at("domains")}: no host serves ${JSON.stringify(locale)} (every locale needs one)`);
|
|
367
|
+
return problems;
|
|
368
|
+
}
|
|
369
|
+
/** Each `routing.paths` entry on its own; `valid` lists the keys whose entry has no problem. */
|
|
370
|
+
function pathEntryProblems(paths, url, locales) {
|
|
371
|
+
const problems = [];
|
|
372
|
+
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
373
|
const valid = [];
|
|
338
|
-
for (const key of
|
|
374
|
+
for (const [key, forms] of Object.entries(paths)) {
|
|
339
375
|
const problem = pathProblem(key);
|
|
340
376
|
if (problem !== null) {
|
|
341
377
|
problems.push(`${at("paths", key)}: ${problem}`);
|
|
342
378
|
continue;
|
|
343
379
|
}
|
|
344
|
-
|
|
345
|
-
for (const [locale, value] of Object.entries(
|
|
380
|
+
const before = problems.length;
|
|
381
|
+
for (const [locale, value] of Object.entries(forms)) {
|
|
346
382
|
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
|
-
}
|
|
383
|
+
if (!locales.includes(locale)) problems.push(`${where}: ${JSON.stringify(locale)} is not in locales`);
|
|
384
|
+
const valueProblem = pathProblem(value);
|
|
385
|
+
if (valueProblem !== null) problems.push(`${where}: ${valueProblem}`);
|
|
386
|
+
else if (wildcards(value) !== wildcards(key)) problems.push(`${where}: must keep the wildcards of ${JSON.stringify(key)}, in order`);
|
|
359
387
|
}
|
|
360
|
-
if (
|
|
388
|
+
if (problems.length === before) valid.push(key);
|
|
361
389
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
390
|
+
return {
|
|
391
|
+
valid,
|
|
392
|
+
problems
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Pairs of valid routes whose forms in one locale are the same path, or
|
|
397
|
+
* overlap where the route paths do not; and, where a locale is unprefixed,
|
|
398
|
+
* a translated path that would read as another route's path.
|
|
399
|
+
*/
|
|
400
|
+
function pathConflictProblems(valid, paths, locales, unprefixed) {
|
|
401
|
+
const problems = [];
|
|
402
|
+
const formOf = (route, locale) => Object.hasOwn(paths[route], locale) ? paths[route][locale] : route;
|
|
403
|
+
const segmentsCache = new Map(valid.map((route) => [route, segmentsOf(route)]));
|
|
404
|
+
const segments = (path) => segmentsCache.get(path) ?? segmentsOf(path);
|
|
405
|
+
for (const locale of locales) {
|
|
367
406
|
for (let i = 0; i < valid.length; i++) {
|
|
368
|
-
const
|
|
369
|
-
const
|
|
407
|
+
const routeA = valid[i];
|
|
408
|
+
const formA = formOf(routeA, locale);
|
|
370
409
|
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(
|
|
410
|
+
const routeB = valid[j];
|
|
411
|
+
const formB = formOf(routeB, locale);
|
|
412
|
+
const where = at("paths", Object.hasOwn(paths[routeB], locale) ? routeB : routeA, locale);
|
|
413
|
+
if (formA === formB) problems.push(`${where}: ${JSON.stringify(routeA)} and ${JSON.stringify(routeB)} share the path ${JSON.stringify(formA)} in ${locale}`);
|
|
414
|
+
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
415
|
}
|
|
377
416
|
}
|
|
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
|
-
}
|
|
417
|
+
if (unprefixed.includes(locale)) problems.push(...unprefixedProblems(valid, paths, locale, segments));
|
|
383
418
|
}
|
|
384
419
|
return problems;
|
|
385
420
|
}
|
|
386
|
-
|
|
387
|
-
|
|
421
|
+
/** Where `locale` is unprefixed, a translated path must not read as another route's path. */
|
|
422
|
+
function unprefixedProblems(valid, paths, locale, segments) {
|
|
423
|
+
const problems = [];
|
|
424
|
+
for (const routeA of valid) for (const routeB of valid) {
|
|
425
|
+
if (routeA === routeB || !Object.hasOwn(paths[routeB], locale)) continue;
|
|
426
|
+
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`);
|
|
427
|
+
}
|
|
428
|
+
return problems;
|
|
429
|
+
}
|
|
430
|
+
// src/core/config/runtime.ts
|
|
431
|
+
/**
|
|
432
|
+
* Pseudo-locales are a development aid: on in `vite dev` and non-production
|
|
433
|
+
* builds (previews, staging), off in production and for the CLI unless
|
|
434
|
+
* `vi18n compile --pseudo` asks for them.
|
|
435
|
+
*/
|
|
436
|
+
function pseudoActive(command, mode) {
|
|
437
|
+
if (command === "serve") return true;
|
|
438
|
+
if (command === "build") return mode !== "production";
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
function toRuntimeConfig(config, options) {
|
|
442
|
+
const pseudoLocales = options.pseudo ? [...config.pseudoLocales] : [];
|
|
443
|
+
const { routing, ssr } = config;
|
|
444
|
+
return {
|
|
445
|
+
sourceLocale: config.sourceLocale,
|
|
446
|
+
locales: [...config.locales, ...pseudoLocales],
|
|
447
|
+
pseudoLocales,
|
|
448
|
+
fallbacks: mapRecord(config.fallbacks, (chain) => [...chain]),
|
|
449
|
+
routing: {
|
|
450
|
+
strategy: [...routing.strategy],
|
|
451
|
+
routeStrategies: mapRecord(routing.routeStrategies, (chain) => [...chain]),
|
|
452
|
+
url: routing.url,
|
|
453
|
+
redirectRoot: routing.redirectRoot,
|
|
454
|
+
propagate: routing.propagate,
|
|
455
|
+
switch: routing.switch,
|
|
456
|
+
cookie: {
|
|
457
|
+
name: routing.cookie.name,
|
|
458
|
+
maxAge: routing.cookie.maxAge
|
|
459
|
+
},
|
|
460
|
+
base: normalizeBase(routing.base ?? options.base),
|
|
461
|
+
...Object.keys(routing.paths).length > 0 && { paths: mapRecord(routing.paths, (entry) => ({ ...entry })) },
|
|
462
|
+
...Object.keys(routing.domains).length > 0 && { domains: mapRecord(routing.domains, (locale) => locale) }
|
|
463
|
+
},
|
|
464
|
+
ssr: {
|
|
465
|
+
timeZone: ssr.timeZone,
|
|
466
|
+
timeZoneFrom: mapRecord(ssr.timeZoneFrom, (source) => source),
|
|
467
|
+
normalizeSpaces: ssr.normalizeSpaces,
|
|
468
|
+
...ssr.payload === "preload" && { payload: "preload" }
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
/** Whether the config localizes paths or routes by domain: the plugin's `__VI18N_ROUTES__`. */
|
|
473
|
+
function hasRoutes(config) {
|
|
474
|
+
return Object.keys(config.routing.paths).length > 0 || Object.keys(config.routing.domains).length > 0;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Vite's `base` as the URL codec needs it: a pathname starting and ending
|
|
478
|
+
* with `/`. A relative base (`""`, `./`) serves the app from wherever it is
|
|
479
|
+
* mounted, which for locale prefixes means the root; a full URL (CDN base)
|
|
480
|
+
* contributes its pathname.
|
|
481
|
+
*/
|
|
482
|
+
function normalizeBase(base) {
|
|
483
|
+
let path = base;
|
|
484
|
+
if (/^[a-z][a-z\d+.-]*:\/\//i.test(path) || path.startsWith("//")) path = new URL(path, "http://localhost").pathname;
|
|
485
|
+
if (path === "" || path === "." || path === "./") return "/";
|
|
486
|
+
if (!path.startsWith("/")) path = "/" + path.replace(/^\.\//, "");
|
|
487
|
+
return path.endsWith("/") ? path : path + "/";
|
|
488
|
+
}
|
|
489
|
+
/** A fresh record of mapped values; `fromEntries` defines properties, so a `__proto__` key stays a key. */
|
|
490
|
+
function mapRecord(record, map) {
|
|
491
|
+
return Object.fromEntries(Object.entries(record).map(([key, value]) => [key, map(value)]));
|
|
492
|
+
}
|
|
493
|
+
// src/core/config/load.ts
|
|
388
494
|
/**
|
|
389
495
|
* Finding, loading and resolving `vi18n.config.ts` (PLAN §5.7, INTERNALS
|
|
390
496
|
* §2.7.1, spike S8). The plugin and the CLI both come through `loadConfig`,
|
|
@@ -578,7 +684,7 @@ function resolveConfig(input, root, configFile) {
|
|
|
578
684
|
}
|
|
579
685
|
function resolveWith(input, root, configFile, inline) {
|
|
580
686
|
root = resolve(root);
|
|
581
|
-
const file = configFile === null ? void 0 :
|
|
687
|
+
const file = configFile === null ? void 0 : displayPath(root, resolve(configFile));
|
|
582
688
|
const result = configSchema.safeParse(input);
|
|
583
689
|
if (!result.success) throw invalid(file, issueLines(result.error.issues).join("; "));
|
|
584
690
|
const user = inline === void 0 ? result.data : {
|
|
@@ -590,73 +696,22 @@ function resolveWith(input, root, configFile, inline) {
|
|
|
590
696
|
const problems = crossFieldProblems(user, sourceLocale, locales);
|
|
591
697
|
if (problems.length > 0) throw invalid(file, problems.join("; "));
|
|
592
698
|
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
699
|
return {
|
|
597
700
|
root,
|
|
598
701
|
configFile: configFile === null ? null : resolve(configFile),
|
|
599
702
|
sourceLocale,
|
|
600
703
|
locales,
|
|
601
704
|
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
|
-
},
|
|
705
|
+
fallbacks: mapRecord(user.fallbacks ?? d.fallbacks, (chain) => [...chain]),
|
|
706
|
+
project: resolveProject(user.project, root),
|
|
707
|
+
extraction: resolveExtraction(user.extraction),
|
|
615
708
|
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
|
-
},
|
|
709
|
+
catalogs: resolveCatalogs(user.catalogs, root),
|
|
622
710
|
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 : {
|
|
711
|
+
routing: resolveRouting(user.routing),
|
|
712
|
+
ssr: resolveSsr(user.ssr),
|
|
713
|
+
ai: resolveAi(user.ai),
|
|
714
|
+
defaults: { tags: mapRecord(user.defaults?.tags ?? d.defaults.tags, (spec) => typeof spec === "string" ? spec : {
|
|
660
715
|
element: spec.element,
|
|
661
716
|
attributes: { ...spec.attributes }
|
|
662
717
|
}) },
|
|
@@ -664,6 +719,87 @@ function resolveWith(input, root, configFile, inline) {
|
|
|
664
719
|
strict: resolveStrict(user.strict)
|
|
665
720
|
};
|
|
666
721
|
}
|
|
722
|
+
function resolveProject(given, root) {
|
|
723
|
+
const d = DEFAULT_CONFIG.project;
|
|
724
|
+
const user = given ?? {};
|
|
725
|
+
return {
|
|
726
|
+
include: (user.include ?? d.include).map((entry) => resolve(root, entry)),
|
|
727
|
+
extensions: [...user.extensions ?? d.extensions],
|
|
728
|
+
exclude: [...user.exclude ?? d.exclude]
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
function resolveExtraction(given) {
|
|
732
|
+
const d = DEFAULT_CONFIG.extraction;
|
|
733
|
+
const user = given ?? {};
|
|
734
|
+
return {
|
|
735
|
+
importSources: [.../* @__PURE__ */ new Set([...DEFAULT_IMPORT_SOURCES, ...user.importSources ?? []])],
|
|
736
|
+
aliases: [...user.aliases ?? d.aliases],
|
|
737
|
+
globals: [...user.globals ?? d.globals],
|
|
738
|
+
keep: [...user.keep ?? d.keep],
|
|
739
|
+
dependencies: [...user.dependencies ?? d.dependencies]
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
function resolveCatalogs(given, root) {
|
|
743
|
+
const d = DEFAULT_CONFIG.catalogs;
|
|
744
|
+
const user = given ?? {};
|
|
745
|
+
const format = user.format ?? d.format;
|
|
746
|
+
const path = user.path ?? (format === "json" ? JSON_CATALOG_PATH : d.path);
|
|
747
|
+
return {
|
|
748
|
+
format,
|
|
749
|
+
path: resolve(root, path),
|
|
750
|
+
msgid: user.msgid ?? d.msgid,
|
|
751
|
+
icuFlag: user.icuFlag ?? d.icuFlag
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
function resolveRouting(given) {
|
|
755
|
+
const d = DEFAULT_CONFIG.routing;
|
|
756
|
+
const user = given ?? {};
|
|
757
|
+
return {
|
|
758
|
+
strategy: [...user.strategy ?? d.strategy],
|
|
759
|
+
routeStrategies: mapRecord(user.routeStrategies ?? d.routeStrategies, (chain) => [...chain]),
|
|
760
|
+
url: user.url ?? d.url,
|
|
761
|
+
redirectRoot: user.redirectRoot ?? d.redirectRoot,
|
|
762
|
+
propagate: user.propagate ?? d.propagate,
|
|
763
|
+
switch: user.switch ?? d.switch,
|
|
764
|
+
cookie: {
|
|
765
|
+
name: user.cookie?.name ?? d.cookie.name,
|
|
766
|
+
maxAge: user.cookie?.maxAge ?? d.cookie.maxAge
|
|
767
|
+
},
|
|
768
|
+
base: user.base ?? d.base,
|
|
769
|
+
paths: mapRecord(user.paths ?? d.paths, (entry) => ({ ...entry })),
|
|
770
|
+
domains: resolveDomains(user.domains ?? d.domains)
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
function resolveSsr(given) {
|
|
774
|
+
const d = DEFAULT_CONFIG.ssr;
|
|
775
|
+
const user = given ?? {};
|
|
776
|
+
return {
|
|
777
|
+
timeZone: user.timeZone ?? d.timeZone,
|
|
778
|
+
timeZoneFrom: mapRecord(user.timeZoneFrom ?? d.timeZoneFrom, (v) => v),
|
|
779
|
+
payload: user.payload ?? d.payload,
|
|
780
|
+
catalogs: user.catalogs ?? d.catalogs,
|
|
781
|
+
maxLoadedLocales: user.maxLoadedLocales ?? d.maxLoadedLocales,
|
|
782
|
+
normalizeSpaces: user.normalizeSpaces ?? d.normalizeSpaces
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
function resolveAi(given) {
|
|
786
|
+
const d = DEFAULT_CONFIG.ai;
|
|
787
|
+
const user = given ?? {};
|
|
788
|
+
const provider = user.provider ?? d.provider;
|
|
789
|
+
return {
|
|
790
|
+
provider,
|
|
791
|
+
model: user.model ?? (typeof provider === "string" ? d.model : provider.model),
|
|
792
|
+
exclude: [...user.exclude ?? d.exclude],
|
|
793
|
+
glossary: mapRecord(user.glossary ?? d.glossary, (targets) => mapRecord(targets, (v) => v)),
|
|
794
|
+
doNotTranslate: [...user.doNotTranslate ?? d.doNotTranslate],
|
|
795
|
+
tone: mapRecord(user.tone ?? d.tone, (v) => v),
|
|
796
|
+
description: user.description ?? d.description,
|
|
797
|
+
apiKeyEnv: user.apiKeyEnv ?? d.apiKeyEnv,
|
|
798
|
+
batchSize: user.batchSize ?? d.batchSize,
|
|
799
|
+
concurrency: user.concurrency ?? d.concurrency,
|
|
800
|
+
dev: user.dev ?? d.dev
|
|
801
|
+
};
|
|
802
|
+
}
|
|
667
803
|
/** Rules between keys, checked once the locale list is known. */
|
|
668
804
|
function crossFieldProblems(user, sourceLocale, locales) {
|
|
669
805
|
const problems = [];
|
|
@@ -700,12 +836,7 @@ function crossFieldProblems(user, sourceLocale, locales) {
|
|
|
700
836
|
function resolveOutput(user) {
|
|
701
837
|
const d = DEFAULT_CONFIG.output;
|
|
702
838
|
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
|
-
},
|
|
839
|
+
split: resolveSplit(user?.split),
|
|
709
840
|
guard: user?.guard ?? d.guard,
|
|
710
841
|
manifestPath: user?.manifestPath ?? d.manifestPath,
|
|
711
842
|
manifest: user?.manifest ?? d.manifest,
|
|
@@ -714,6 +845,16 @@ function resolveOutput(user) {
|
|
|
714
845
|
perLocale: user?.perLocale ?? d.perLocale
|
|
715
846
|
};
|
|
716
847
|
}
|
|
848
|
+
function resolveSplit(given) {
|
|
849
|
+
const d = DEFAULT_CONFIG.output.split;
|
|
850
|
+
const user = given ?? {};
|
|
851
|
+
return {
|
|
852
|
+
shared: user.shared ?? d.shared,
|
|
853
|
+
dupBelow: user.dupBelow ?? d.dupBelow,
|
|
854
|
+
minBytes: user.minBytes ?? d.minBytes,
|
|
855
|
+
maxBundlesPerRoot: user.maxBundlesPerRoot === void 0 ? d.maxBundlesPerRoot : user.maxBundlesPerRoot
|
|
856
|
+
};
|
|
857
|
+
}
|
|
717
858
|
function resolveStrict(strict) {
|
|
718
859
|
const d = DEFAULT_CONFIG.strict;
|
|
719
860
|
if (strict === true) return {
|
|
@@ -722,26 +863,10 @@ function resolveStrict(strict) {
|
|
|
722
863
|
moduleScope: "error"
|
|
723
864
|
};
|
|
724
865
|
if (strict === void 0 || strict === false) return { ...d };
|
|
725
|
-
const pick = (value, fallback) => value ?? fallback;
|
|
726
866
|
return {
|
|
727
|
-
missing:
|
|
728
|
-
invalid:
|
|
729
|
-
moduleScope:
|
|
867
|
+
missing: strict.missing ?? d.missing,
|
|
868
|
+
invalid: strict.invalid ?? d.invalid,
|
|
869
|
+
moduleScope: strict.moduleScope ?? d.moduleScope
|
|
730
870
|
};
|
|
731
871
|
}
|
|
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 };
|
|
872
|
+
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 };
|