@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.
Files changed (121) hide show
  1. package/README.md +19 -0
  2. package/dist/{apply-Bre-lY9J.js → apply-Bg-3rB2m.js} +69 -89
  3. package/dist/{captured-Bj8bO6vd.js → captured-DfLk50Ji.js} +196 -217
  4. package/dist/{check-BIKEuu6B.js → check-CunekuYs.js} +76 -85
  5. package/dist/cli.js +2 -3
  6. package/dist/{collect-Cx4_SKOe.js → collect-CYATDjdo.js} +1 -2
  7. package/dist/collisions-CDSdtLQm.js +215 -0
  8. package/dist/{compile-Cc97JaW2.js → compile-DqkofbiO.js} +376 -331
  9. package/dist/compile-hva0qjhZ.js +240 -0
  10. package/dist/concurrency-BCY_4zcr.js +1 -0
  11. package/dist/concurrency-Dy2ny50V.js +107 -0
  12. package/dist/config.d.ts +1 -5
  13. package/dist/config.js +4 -5
  14. package/dist/{types-D3QGM8XO.js → diagnostics-LgIWyeSp.js} +28 -27
  15. package/dist/{dir-zw6bGMKQ.js → dir-TGLYuOZb.js} +34 -37
  16. package/dist/{duplicates-yuRljQ6h.js → duplicates-8cudcHNj.js} +10 -27
  17. package/dist/engine-ecRD8-IE.js +556 -0
  18. package/dist/engine.d.ts +1 -5
  19. package/dist/engine.js +297 -168
  20. package/dist/exchange-DjwlrTQ9.js +41 -0
  21. package/dist/{exclude-Du-Zd_qI.js → exclude-BFETmvde.js} +2 -3
  22. package/dist/{export-C9Sy6UWv.js → export-D2tsqWIr.js} +17 -38
  23. package/dist/{extract-C3S8btx0.js → extract-BxYchVmY.js} +114 -82
  24. package/dist/{formats-9unqj_fZ.js → formats-BaryZ2N7.js} +352 -276
  25. package/dist/fs-ezCMZeDV.js +52 -0
  26. package/dist/i18next-COO6o0tX.js +1907 -0
  27. package/dist/i18next-Dr7DCQlQ.js +1 -0
  28. package/dist/{import-nANvQutw.js → import-vSC29Cn4.js} +81 -75
  29. package/dist/index.d.ts +1 -13
  30. package/dist/index.js +14 -16
  31. package/dist/{init-C2ScuW6a.js → init-Cc7A-8VX.js} +466 -501
  32. package/dist/{library-D5CWvTQs.js → library-tp_xqzSY.js} +975 -451
  33. package/dist/lingui-BnnlqGXT.js +902 -0
  34. package/dist/lint.d.ts +0 -4
  35. package/dist/lint.js +70 -82
  36. package/dist/{load-gW-oJt1Q.js → load-BSIeGJ5v.js} +275 -148
  37. package/dist/{load-CQRz4PpM.js → load-SSrAeJVB.js} +1214 -1116
  38. package/dist/{locales-DX4MOBFE.js → locales-D0U-yVRm.js} +271 -237
  39. package/dist/{lsp-RMMMc88P.js → lsp-DvC11pBZ.js} +4 -5
  40. package/dist/{match-BGr8EXB3.js → match-BLDcj610.js} +11 -4
  41. package/dist/{mcp-CHVwBoRP.js → mcp-D2zzOTBy.js} +4 -5
  42. package/dist/{merge-driver-BTX87aVm.js → merge-driver-BLI8OtAc.js} +138 -122
  43. package/dist/migrate-1r43OBfe.js +1 -0
  44. package/dist/migrate-ChDGhlC-.js +2169 -0
  45. package/dist/{openai-CTaMDcl-.js → openai-CLn4puY8.js} +128 -87
  46. package/dist/{output-DWE3SIUA.js → output-D5tAt8q4.js} +15 -9
  47. package/dist/parse.d.ts +1 -3
  48. package/dist/parse.js +7 -8
  49. package/dist/{pipeline-C9Dbotkh.js → pipeline-BJSkkRYC.js} +387 -359
  50. package/dist/{pipeline-DbX6rlo5.js → pipeline-BeCc441z.js} +1 -1
  51. package/dist/project-B5KIO0q-.js +544 -0
  52. package/dist/{pseudo-DRv30iN5.js → pseudo-B2DUpoLu.js} +126 -3
  53. package/dist/{raw-C4Y6vyGY.js → raw-YsYZMS9n.js} +52 -29
  54. package/dist/react-intl-C8JehBBL.js +634 -0
  55. package/dist/rename-ZVGq9ZG1.js +577 -0
  56. package/dist/repeated-uuI1tUGg.js +85 -0
  57. package/dist/restore-xlBIrtRt.js +199 -0
  58. package/dist/rewrite-BwzXoBiA.js +415 -0
  59. package/dist/{rich-DCUKl5HM.js → rich-ApY1Dm4S.js} +35 -28
  60. package/dist/rolldown-runtime-C1I3wEg2.js +43 -0
  61. package/dist/{rolldown-runtime-D7D4PA-g.js → rolldown-runtime-D8jQpDG7.js} +1 -2
  62. package/dist/run-CQ9pDLSa.js +674 -0
  63. package/dist/scan-worker.d.ts +2 -4
  64. package/dist/scan-worker.js +1 -1
  65. package/dist/{scoped-BMYpSthj.js → scoped-h3KE8XWW.js} +3 -4
  66. package/dist/{server-Da1Ot9IN.js → server-Br8tAuG2.js} +312 -386
  67. package/dist/{server-deBOq2vq.js → server-DJRpUQVZ.js} +1059 -333
  68. package/dist/server.d.ts +1 -17
  69. package/dist/server.js +419 -379
  70. package/dist/{sitemap-DJXzKoza.js → sitemap-CSAkm6oi.js} +21 -33
  71. package/dist/{sources-D19czDSA.js → sources-DNVbYsgs.js} +713 -373
  72. package/dist/{status-zr4jY59Y.js → status-q6M3rBrh.js} +30 -30
  73. package/dist/{stdio-FPOKQAgu.js → stdio-D9kTzyqB.js} +2 -4
  74. package/dist/{stdio-CVaJfxA7.js → stdio-FWIVU3P4.js} +1 -2
  75. package/dist/sync-BNIAwMhR.js +1352 -0
  76. package/dist/{t-DC-c9zE5.js → t-gvEXx25s.js} +76 -53
  77. package/dist/test.d.ts +5 -16
  78. package/dist/test.js +126 -56
  79. package/dist/translate-BP4iVhOR.js +336 -0
  80. package/dist/{ts-BaU5yOf0.js → ts-BX6kwig5.js} +25 -14
  81. package/dist/{types-DtvQ7UdD.js → types-3kwyaCAm.js} +1 -2
  82. package/dist/{types-DsdWBG0b.d.ts → types-B4wNX6PA.d.ts} +6 -8
  83. package/dist/{types-CgUCkFU1.d.ts → types-_4UdFhR9.d.ts} +24 -21
  84. package/dist/types-xR2exI3L.js +42 -0
  85. package/dist/{units-CQ5Q99RC.js → units-DPPfCN7j.js} +7 -16
  86. package/dist/{url-CRfCOhUI.js → url-Bpc6wLea.js} +24 -11
  87. package/dist/{url-CsBkRaJy.js → url-D2_VlEeH.js} +25 -12
  88. package/dist/{validate-BxpupdAf.js → validate-CgzaDdOY.js} +690 -377
  89. package/dist/{validate-D6DJepZv.js → validate-PGgMsasz.js} +3 -5
  90. package/dist/{version-Byqi2guX.js → version-DC-J5WvV.js} +3 -5
  91. package/dist/{vite-scan-CT_vsp4g.js → vite-scan-kM8Ta3rO.js} +87 -92
  92. package/dist/vite.d.ts +2 -6
  93. package/dist/vite.js +6500 -6032
  94. package/dist/vue-i18n-_uIXlFVh.js +806 -0
  95. package/dist/{which-BOemZ5Q8.js → which-DFWk_KwN.js} +44 -37
  96. package/dist/{worker-84U6uYB3.js → worker-zlhNj4y3.js} +454 -608
  97. package/package.json +5 -5
  98. package/dist/check-HsmmpJZg.js +0 -1
  99. package/dist/codec-DuvU2VQy.js +0 -207
  100. package/dist/collisions-CfpZU8e4.js +0 -217
  101. package/dist/compile-BaDh0cHG.js +0 -245
  102. package/dist/concurrency-C9UUWuDC.js +0 -96
  103. package/dist/concurrency-DONL7t4V.js +0 -1
  104. package/dist/engine-C2ENBRJe.js +0 -531
  105. package/dist/i18next-9HAoxwUI.js +0 -1
  106. package/dist/i18next-BEJgv_S8.js +0 -1596
  107. package/dist/lingui-zUiCl9Um.js +0 -833
  108. package/dist/messages-BfjIExyB.js +0 -166
  109. package/dist/migrate-IpLDMXmq.js +0 -1484
  110. package/dist/migrate-rCQuOGsf.js +0 -1
  111. package/dist/project-Bw9UPIdx.js +0 -1046
  112. package/dist/project-C4GpaN-n.js +0 -381
  113. package/dist/react-intl-BP0u-D5m.js +0 -519
  114. package/dist/restore-CiYv-jxS.js +0 -175
  115. package/dist/rewrite-EsIw_lsq.js +0 -803
  116. package/dist/run-BEcnBbu-.js +0 -694
  117. package/dist/runtime-DTMmliT1.js +0 -64
  118. package/dist/sync-B9V2KFwb.js +0 -658
  119. package/dist/translate-CQnJfLjO.js +0 -299
  120. package/dist/types-wSh9fCBY.js +0 -11
  121. package/dist/vue-i18n-g0iGy6CZ.js +0 -651
@@ -1 +1 @@
1
- export { t as MAX_RETRIES, n as catalogPersister, r as createProvider, i as estimateUsage, a as firstRequests, o as planTranslations, s as replayProvider, c as runTranslations } from "./pipeline-C9Dbotkh.js";
1
+ export { t as MAX_RETRIES, n as catalogPersister, r as createProvider, i as estimateUsage, a as firstRequests, o as planTranslations, s as replayProvider, c as runTranslations } from "./pipeline-BJSkkRYC.js";
@@ -0,0 +1,544 @@
1
+ import { A as usableTranslation, E as entryKey, i as libraryTranslation, l as loadCatalogSet, o as catalogLayout, s as catalogPath } from "./library-tp_xqzSY.js";
2
+ import { g as isManualId, p as createCodec, r as validateTranslation } from "./validate-CgzaDdOY.js";
3
+ import { r as loadConfig } from "./load-BSIeGJ5v.js";
4
+ import { n as isDiagnosticError } from "./diagnostics-LgIWyeSp.js";
5
+ import { i as genFileUpToDate, n as syncCatalogs, r as GEN_FILE, s as scanProject } from "./sync-BNIAwMhR.js";
6
+ import { i as rootRelative, o as errorMessage, r as plural } from "./output-D5tAt8q4.js";
7
+ import { r as resolveDuplicates, t as duplicateDiagnostics } from "./duplicates-8cudcHNj.js";
8
+ import { r as EXIT } from "./types-xR2exI3L.js";
9
+ import { dirname, join } from "node:path";
10
+ import { readFile } from "node:fs/promises";
11
+ // src/cli/diagnostics.ts
12
+ /**
13
+ * Diagnostics more than one surface reports with the same words: `check`,
14
+ * `extract --check`, the language server, the MCP tools and the migrators.
15
+ * Each is built here once, so the surfaces cannot drift apart.
16
+ */
17
+ /** Wrapped lines and foreign contexts of one catalog entry; the language server reports them on open catalogs too. */
18
+ function syntaxOfEntry(into, entry, file, locale) {
19
+ if (entry.wrapped) into.push({
20
+ code: "catalog-wrapped",
21
+ severity: "warning",
22
+ message: "a string is wrapped over several lines; vi18n extract rewrites it on one line",
23
+ file,
24
+ line: entry.line,
25
+ locale
26
+ });
27
+ if (entry.foreignContext !== null) into.push({
28
+ code: "catalog-foreign-context",
29
+ severity: "warning",
30
+ message: `msgctxt "${entry.foreignContext}" is not a manual id (no "."), so no message matches this entry; give it a manual id with a "." or remove it`,
31
+ file,
32
+ line: entry.line,
33
+ locale
34
+ });
35
+ }
36
+ /** A catalog that records another id scheme than `ids.length` gives; null when the schemes agree (or none is recorded). */
37
+ function idSchemeMismatch(project, file, locale, recorded) {
38
+ const { config, codec } = project;
39
+ if (recorded === null || recorded === codec.idScheme) return null;
40
+ return {
41
+ code: "id-scheme-mismatch",
42
+ severity: "error",
43
+ message: `${file} records ${recorded}, but ids.length ${config.ids.length} gives ${codec.idScheme}; run vi18n extract to re-key it (translations are kept)`,
44
+ file,
45
+ locale
46
+ };
47
+ }
48
+ /**
49
+ * A translation against its source: why it does not parse, or every finding
50
+ * of `validateTranslation` (errors and warnings). Callers place and grade
51
+ * them; positions inside the text mean nothing in a catalog.
52
+ */
53
+ function checkTranslation(codec, input) {
54
+ let parsed;
55
+ try {
56
+ parsed = codec.parse(input.translation);
57
+ } catch (error) {
58
+ if (!isDiagnosticError(error)) throw error;
59
+ return {
60
+ parseError: error.diagnostic,
61
+ findings: []
62
+ };
63
+ }
64
+ const options = {
65
+ locale: input.locale,
66
+ text: input.translation
67
+ };
68
+ if (input.maxLength !== void 0 && input.maxLength !== null) options.maxLength = input.maxLength;
69
+ return {
70
+ parseError: null,
71
+ findings: validateTranslation(parsed, input.source, options)
72
+ };
73
+ }
74
+ // src/cli/messages.ts
75
+ /**
76
+ * One message across every locale (INTERNALS §2.17): its source, where the
77
+ * code uses it, and each locale's own entry with the state
78
+ * `usableTranslation` gives it. The read model the language server's
79
+ * hovers, diagnostics and definitions and the MCP server's translation tools
80
+ * share, built like `status` and `check` build theirs (a locale's own entry,
81
+ * no fallbacks), so every surface reports one state for one entry.
82
+ */
83
+ function indexCatalog(project, locale, path, catalog, hash) {
84
+ const { config, codec, layout } = project;
85
+ const file = rootRelative(config.root, path);
86
+ const index = {
87
+ locale,
88
+ path,
89
+ file,
90
+ hash,
91
+ catalog,
92
+ entries: /* @__PURE__ */ new Map(),
93
+ schemeMismatch: false,
94
+ diagnostics: []
95
+ };
96
+ if (catalog === null) return index;
97
+ const resolved = resolveDuplicates(catalog, codec);
98
+ index.diagnostics = duplicateDiagnostics(resolved.duplicates, file);
99
+ for (const entry of resolved.catalog.entries) {
100
+ const key = entryKey(entry, layout, codec);
101
+ if (key !== null && !index.entries.has(key)) index.entries.set(key, entry);
102
+ }
103
+ index.schemeMismatch = layout !== "source" && catalog.header.idScheme !== null && catalog.header.idScheme !== codec.idScheme;
104
+ return index;
105
+ }
106
+ /** Every configured locale's index, the source locale first. */
107
+ function indexCatalogs(project, set) {
108
+ const indexes = /* @__PURE__ */ new Map();
109
+ for (const locale of localeOrder(project)) {
110
+ const loaded = set.get(locale);
111
+ if (loaded === void 0) continue;
112
+ indexes.set(locale, indexCatalog(project, locale, loaded.path, loaded.catalog, loaded.hash));
113
+ }
114
+ return indexes;
115
+ }
116
+ /**
117
+ * Whether a recorded id scheme other than the codec's hides this message's
118
+ * entry: every generated id, and "id"-layout manual entries, which store a
119
+ * scheme-dependent label too (INTERNALS §2.8.2).
120
+ */
121
+ function affectedBySchemeMismatch(index, layout, identity) {
122
+ return index.schemeMismatch && (layout === "id" || !identity.manual);
123
+ }
124
+ /** The source locale, then the others in config order. */
125
+ function localeOrder(project) {
126
+ const { config } = project;
127
+ return [config.sourceLocale, ...config.locales.filter((l) => l !== config.sourceLocale)];
128
+ }
129
+ /**
130
+ * One locale's own entry for a message: the source locale shows the source,
131
+ * a target locale the state `usableTranslation` decides (`scheme-mismatch`
132
+ * and `no-entry` as `ownStatus` decides them).
133
+ */
134
+ function localeView(project, index, identity) {
135
+ const { config, codec, layout } = project;
136
+ const entry = index.entries.get(identity.id);
137
+ const view = {
138
+ locale: index.locale,
139
+ state: "missing",
140
+ text: null,
141
+ fuzzy: entry?.fuzzy ?? false,
142
+ file: index.file,
143
+ line: entry !== void 0 && entry.line > 0 ? entry.line : null,
144
+ diagnostics: []
145
+ };
146
+ if (index.locale === config.sourceLocale) {
147
+ view.state = "source";
148
+ view.text = identity.canonical;
149
+ return view;
150
+ }
151
+ if (affectedBySchemeMismatch(index, layout, identity)) {
152
+ view.reason = "scheme-mismatch";
153
+ return view;
154
+ }
155
+ if (entry === void 0) {
156
+ view.reason = "no-entry";
157
+ return view;
158
+ }
159
+ if (entry.translation !== "") view.text = entry.translation;
160
+ const usable = usableTranslation(entry, layout, identity, codec, index.locale);
161
+ if (usable.ok) {
162
+ view.state = entry.state === "ai" ? "ai" : "translated";
163
+ return view;
164
+ }
165
+ view.reason = usable.reason;
166
+ for (const diagnostic of usable.diagnostics) view.diagnostics.push({
167
+ ...diagnostic,
168
+ file: index.file
169
+ });
170
+ return view;
171
+ }
172
+ /** A message with every locale's view; `extracted` adds the code's notes and call sites. */
173
+ function messageView(project, indexes, identity, extracted) {
174
+ const { config } = project;
175
+ let contexts = extracted?.contexts.slice() ?? [];
176
+ let maxLength = extracted?.maxLength ?? null;
177
+ if (extracted === void 0) for (const index of indexes.values()) {
178
+ const entry = index.entries.get(identity.id);
179
+ if (entry === void 0) continue;
180
+ contexts = entry.contexts.slice();
181
+ maxLength = entry.maxLength;
182
+ break;
183
+ }
184
+ const locales = [];
185
+ for (const locale of localeOrder(project)) {
186
+ const index = indexes.get(locale);
187
+ if (index !== void 0) locales.push(localeView(project, index, identity));
188
+ }
189
+ return {
190
+ id: identity.id,
191
+ manual: identity.manual,
192
+ source: identity.canonical,
193
+ contexts,
194
+ maxLength,
195
+ keep: config.extraction.keep.includes(identity.id),
196
+ locations: extracted?.locations.map((l) => ({ ...l })) ?? [],
197
+ locales
198
+ };
199
+ }
200
+ // src/cli/project.ts
201
+ /**
202
+ * What several commands share: loading the config (exit 2 without one, so a
203
+ * typo in `--cwd` never "succeeds" on an empty project), the cached include
204
+ * scan, the catalog set, the referenced messages (code plus `keep` ids), each
205
+ * locale's own-entry status, and the drift `extract --check` and `compile`
206
+ * refuse to run past.
207
+ */
208
+ /** Ends a command early with an exit code; `run` reports the diagnostics and prints the envelope. */
209
+ var CliExit = class extends Error {
210
+ exitCode;
211
+ diagnostics;
212
+ data;
213
+ constructor(exitCode, diagnostics = [], data = null) {
214
+ super(diagnostics[0]?.message ?? `exit ${exitCode}`);
215
+ this.exitCode = exitCode;
216
+ this.diagnostics = diagnostics;
217
+ this.data = data;
218
+ }
219
+ };
220
+ /** A bad flag or a config the command cannot use (exit 2). */
221
+ function usageError(message) {
222
+ return new CliExit(EXIT.usage, [{
223
+ code: "config-invalid",
224
+ severity: "error",
225
+ message
226
+ }]);
227
+ }
228
+ /** The codec and catalog layout a resolved config implies. */
229
+ function projectOf(config) {
230
+ return {
231
+ config,
232
+ codec: createCodec(config.ids.length),
233
+ layout: catalogLayout(config)
234
+ };
235
+ }
236
+ async function loadProject(ctx) {
237
+ let config;
238
+ try {
239
+ config = await loadConfig({
240
+ cwd: ctx.global.cwd,
241
+ configFile: ctx.global.config
242
+ });
243
+ } catch (error) {
244
+ if (isDiagnosticError(error)) throw new CliExit(EXIT.usage, [error.diagnostic]);
245
+ throw usageError(`vi18n.config.ts could not be loaded: ${errorMessage(error)}`);
246
+ }
247
+ if (config.configFile === null) throw new CliExit(EXIT.usage, [{
248
+ code: "config-not-found",
249
+ severity: "error",
250
+ message: `no vi18n.config.ts in ${ctx.global.cwd} or any directory above it up to the workspace root; run vi18n init`
251
+ }]);
252
+ ctx.out.setRoot(config.root);
253
+ ctx.out.addSecret(ctx.io.env[config.ai.apiKeyEnv]);
254
+ return {
255
+ ...projectOf(config),
256
+ genPath: join(dirname(config.configFile), GEN_FILE)
257
+ };
258
+ }
259
+ /**
260
+ * The cached include scan, or with `vite` the scan through the project's
261
+ * Vite config (`extract --vite`); an aborted scan (parse error, missing
262
+ * compiler, empty root) ends the command.
263
+ */
264
+ async function scan(project, options = {}) {
265
+ const result = options.vite === true ? await (await import("./vite-scan-kM8Ta3rO.js")).scanWithVite(project.config) : await scanProject(project.config, project.codec, { cache: true });
266
+ if (result.aborted) throw new CliExit(EXIT.failure, result.diagnostics.filter(isAbortCause));
267
+ return result;
268
+ }
269
+ function isAbortCause(diagnostic) {
270
+ return diagnostic.severity === "error";
271
+ }
272
+ async function loadCatalogs(project) {
273
+ return loadCatalogSet(project.config, project.codec);
274
+ }
275
+ /** Every occurrence with its location, as `findCollisions` wants them (aggregation keeps only the first text of an id). */
276
+ function occurrencesOf(scanned) {
277
+ const list = [];
278
+ for (const file of scanned.files) for (const occurrence of file.occurrences) list.push({
279
+ id: occurrence.id,
280
+ manual: occurrence.manual,
281
+ canonical: occurrence.canonical,
282
+ sourceHash: occurrence.sourceHash,
283
+ label: occurrence.label,
284
+ source: occurrence.source,
285
+ locations: [{
286
+ file: occurrence.file,
287
+ line: occurrence.line
288
+ }]
289
+ });
290
+ return list;
291
+ }
292
+ /**
293
+ * The messages a locale must cover: the scan's, plus `keep` ids no code
294
+ * declares, whose text comes from the source locale's entry (else any
295
+ * locale's), as `compileLocales` resolves them. A `keep` id with no entry
296
+ * anywhere is `keep-missing-entry`.
297
+ */
298
+ function referencedMessages(project, messages, set) {
299
+ const { config, codec } = project;
300
+ const identities = /* @__PURE__ */ new Map();
301
+ for (const [id, message] of messages) identities.set(id, message);
302
+ const diagnostics = [];
303
+ const wanted = config.extraction.keep.filter((id) => !identities.has(id));
304
+ if (wanted.length === 0) return {
305
+ identities,
306
+ diagnostics
307
+ };
308
+ const order = localeOrder(project);
309
+ for (const id of wanted) {
310
+ const text = keptSource(project, set, order, id);
311
+ if (text === null) {
312
+ diagnostics.push({
313
+ code: "keep-missing-entry",
314
+ severity: "error",
315
+ message: `extraction.keep lists ${id}, but no code declares it and no catalog has an entry for it; add msg({ id: "${id}", message: "…" }) to the code or remove it from keep`,
316
+ id
317
+ });
318
+ continue;
319
+ }
320
+ try {
321
+ const canonical = codec.canonicalize(text);
322
+ identities.set(id, {
323
+ id,
324
+ manual: isManualId(id),
325
+ canonical,
326
+ sourceHash: codec.sourceHash(canonical),
327
+ label: codec.label(canonical)
328
+ });
329
+ } catch (error) {
330
+ if (!isDiagnosticError(error)) throw error;
331
+ }
332
+ }
333
+ return {
334
+ identities,
335
+ diagnostics
336
+ };
337
+ }
338
+ /** The source text of a `keep` id: the first locale in `order` whose catalog has an entry for it. */
339
+ function keptSource(project, set, order, id) {
340
+ const { codec, layout } = project;
341
+ for (const locale of order) for (const entry of set.get(locale)?.catalog?.entries ?? []) if (entry.source !== null && entryKey(entry, layout, codec) === id) return entry.source;
342
+ return null;
343
+ }
344
+ /**
345
+ * The locale's **own** entries against the referenced messages: the one
346
+ * definition (`usableTranslation`) that compilation, `check` and `status`
347
+ * share, without walking fallbacks — a fallback hides a gap, it does not
348
+ * fill it.
349
+ */
350
+ function ownStatus(project, locale, loaded, identities) {
351
+ const { codec, layout } = project;
352
+ const index = indexCatalog(project, locale, loaded?.path ?? catalogPath(project.config, locale), loaded?.catalog ?? null, null);
353
+ const status = {
354
+ locale,
355
+ total: identities.size,
356
+ translated: 0,
357
+ ai: 0,
358
+ missing: 0,
359
+ reasons: /* @__PURE__ */ new Map(),
360
+ invalid: [],
361
+ diagnostics: [...index.diagnostics],
362
+ schemeMismatch: index.schemeMismatch,
363
+ entries: /* @__PURE__ */ new Map()
364
+ };
365
+ const count = (state) => {
366
+ if (state === "ai") status.ai++;
367
+ else status.translated++;
368
+ };
369
+ const miss = (id, reason) => {
370
+ status.missing++;
371
+ status.reasons.set(id, reason);
372
+ };
373
+ const library = (identity) => {
374
+ const found = libraryTranslation(loaded, identity, layout, codec);
375
+ if (found !== null) count(found.state);
376
+ return found !== null;
377
+ };
378
+ for (const [id, identity] of identities) {
379
+ if (affectedBySchemeMismatch(index, layout, identity)) {
380
+ miss(id, "scheme-mismatch");
381
+ continue;
382
+ }
383
+ const entry = index.entries.get(id);
384
+ if (entry === void 0) {
385
+ if (!library(identity)) miss(id, "no-entry");
386
+ continue;
387
+ }
388
+ status.entries.set(id, entry);
389
+ const usable = usableTranslation(entry, layout, identity, codec, locale);
390
+ if (usable.ok) {
391
+ count(entry.state);
392
+ continue;
393
+ }
394
+ if (entry.translation === "" && library(identity)) continue;
395
+ miss(id, usable.reason);
396
+ if (usable.reason === "invalid" || usable.reason === "fuzzy") status.invalid.push({
397
+ id,
398
+ reason: usable.reason,
399
+ line: entry.line
400
+ });
401
+ status.diagnostics.push(...usable.diagnostics);
402
+ }
403
+ return status;
404
+ }
405
+ /** (translated + ai) / total × 100 with one decimal; an empty locale has nothing left to do. */
406
+ function percent(done, total) {
407
+ if (total === 0) return 100;
408
+ return Math.round(done / total * 1e3) / 10;
409
+ }
410
+ /** Unused-entry warnings listed per locale; the rest is counted in the drift message. */
411
+ const UNUSED_LISTED = 20;
412
+ /**
413
+ * What `vi18n extract` would change, without writing (`extract --check`,
414
+ * and `compile`'s refusal). The safety limit does not apply: drift is drift
415
+ * whether or not extract would need `--yes` to fix it.
416
+ */
417
+ async function computeDrift(project, messages, set) {
418
+ const { config, codec } = project;
419
+ const sync = syncCatalogs({
420
+ config,
421
+ codec,
422
+ messages,
423
+ catalogs: set,
424
+ options: {
425
+ mode: "full",
426
+ yes: true
427
+ }
428
+ });
429
+ const diagnostics = [];
430
+ const referenced = {
431
+ messages,
432
+ keep: new Set(config.extraction.keep)
433
+ };
434
+ for (const locale of config.locales) diagnostics.push(...localeDrift(project, locale, set.get(locale), referenced, sync));
435
+ const gen = await genDrift(config, project.genPath);
436
+ if (gen !== null) diagnostics.push({
437
+ code: "catalog-drift",
438
+ severity: "error",
439
+ message: gen === "missing" ? `${GEN_FILE} does not exist yet; run vi18n extract` : `${GEN_FILE} differs from what vi18n extract writes for the configured locales (edited by hand, or the locales changed); run vi18n extract`,
440
+ file: rootRelative(config.root, project.genPath)
441
+ });
442
+ return {
443
+ sync,
444
+ locales: sync.changed,
445
+ gen: gen !== null,
446
+ diagnostics
447
+ };
448
+ }
449
+ /** One locale's drift: the details (scheme, wrapped, foreign, unused), then `catalog-drift` when extract would rewrite it. */
450
+ function localeDrift(project, locale, loaded, { messages, keep }, sync) {
451
+ const { config, codec, layout } = project;
452
+ const file = catalogFile(config, locale, loaded);
453
+ const read = loaded?.catalog ?? null;
454
+ const diagnostics = [];
455
+ let wrapped = 0;
456
+ let unused = 0;
457
+ if (read !== null) {
458
+ const scheme = idSchemeMismatch(project, file, locale, read.header.idScheme);
459
+ if (scheme !== null) diagnostics.push(scheme);
460
+ for (const entry of read.entries) {
461
+ if (entry.wrapped) wrapped++;
462
+ syntaxOfEntry(diagnostics, entry, file, locale);
463
+ if (entry.foreignContext !== null) continue;
464
+ const key = entryKey(entry, layout, codec);
465
+ if (key === null || messages.has(key) || keep.has(key)) continue;
466
+ unused++;
467
+ if (unused > UNUSED_LISTED) continue;
468
+ diagnostics.push({
469
+ code: "catalog-unused-entry",
470
+ severity: "warning",
471
+ message: `${key} is not referenced by the code; vi18n extract deletes it`,
472
+ file,
473
+ line: entry.line,
474
+ locale,
475
+ id: key
476
+ });
477
+ }
478
+ }
479
+ if (!sync.changed.includes(locale)) return diagnostics;
480
+ diagnostics.push({
481
+ code: "catalog-drift",
482
+ severity: "error",
483
+ message: read === null ? `${file} does not exist yet; run vi18n extract` : `${file} is out of date (${driftSummary(sync.stats[locale], wrapped, unused)}); run vi18n extract`,
484
+ file,
485
+ locale
486
+ });
487
+ return diagnostics;
488
+ }
489
+ function driftSummary(stats, wrapped, unused) {
490
+ const parts = [];
491
+ if (stats !== void 0) {
492
+ if (stats.added > 0) parts.push(`${stats.added} to add`);
493
+ if (stats.deleted > 0) parts.push(`${stats.deleted} to delete`);
494
+ if (stats.cleared > 0) parts.push(`${stats.cleared} to clear`);
495
+ if (stats.moved > 0) parts.push(`${stats.moved} to move`);
496
+ if (stats.rekeyed > 0) parts.push(`${stats.rekeyed} to re-key`);
497
+ if (stats.updated > 0) parts.push(`${stats.updated} to update`);
498
+ }
499
+ if (wrapped > 0) parts.push(plural(wrapped, "wrapped entry", "wrapped entries"));
500
+ if (unused > UNUSED_LISTED) parts.push(`${unused} unused entries, ${UNUSED_LISTED} listed`);
501
+ return parts.length === 0 ? "formatting or header" : parts.join(", ");
502
+ }
503
+ /** Null when `vi18n.gen.ts` is up to date (an earlier release's content for the same locales counts). */
504
+ async function genDrift(config, path) {
505
+ try {
506
+ return genFileUpToDate(config, await readFile(path, "utf8")) ? null : "stale";
507
+ } catch (error) {
508
+ if (error.code === "ENOENT") return "missing";
509
+ throw error;
510
+ }
511
+ }
512
+ /** Catalog read errors make every writer refuse: rewriting a file vi18n cannot fully read drops what it skipped. */
513
+ function readErrors(diagnostics) {
514
+ return diagnostics.filter((d) => d.code === "catalog-parse" && d.severity === "error");
515
+ }
516
+ /**
517
+ * Target locales from `--locale` (default: every configured locale but the
518
+ * source); unknown ones are usage errors, and so is the source locale unless
519
+ * `includeSource` allows naming it.
520
+ */
521
+ function targetLocales(config, requested, options = {}) {
522
+ const targets = config.locales.filter((locale) => locale !== config.sourceLocale);
523
+ if (requested.length === 0) return targets;
524
+ const out = [];
525
+ for (const locale of requested) {
526
+ if (locale === config.sourceLocale && options.includeSource !== true) throw usageError(`--locale ${locale} is the source locale, which is compiled from code and has nothing to translate`);
527
+ if (!config.locales.includes(locale)) throw usageError(`--locale ${locale} is not in locales (${config.locales.join(", ")})`);
528
+ if (!out.includes(locale)) out.push(locale);
529
+ }
530
+ return out;
531
+ }
532
+ function hasErrors(diagnostics) {
533
+ return diagnostics.some((diagnostic) => diagnostic.severity === "error");
534
+ }
535
+ /** UTF-16 code-unit order, as every vi18n file uses. */
536
+ function compareText(a, b) {
537
+ if (a === b) return 0;
538
+ return a < b ? -1 : 1;
539
+ }
540
+ /** A locale's catalog file as diagnostics name it: posix, relative to the config root. */
541
+ function catalogFile(config, locale, loaded) {
542
+ return rootRelative(config.root, loaded?.path ?? catalogPath(config, locale));
543
+ }
544
+ export { idSchemeMismatch as C, checkTranslation as S, indexCatalog as _, hasErrors as a, localeView as b, occurrencesOf as c, projectOf as d, readErrors as f, usageError as g, targetLocales as h, computeDrift as i, ownStatus as l, scan as m, catalogFile as n, loadCatalogs as o, referencedMessages as p, compareText as r, loadProject as s, CliExit as t, percent as u, indexCatalogs as v, syntaxOfEntry as w, messageView as x, localeOrder as y };
@@ -1,4 +1,128 @@
1
- //#region src/core/ir/pseudo.ts
1
+ // src/config/types.ts
2
+ /** The two generated pseudo-locales (PLAN §4.7, §5.21). */
3
+ const PSEUDO_LOCALES = ["en-XA", "ar-XB"];
4
+ /** The only config file name (revision 4.2). */
5
+ const CONFIG_FILE = "vi18n.config.ts";
6
+ /** Import sources that always apply; `extraction.importSources` is appended to them. */
7
+ const DEFAULT_IMPORT_SOURCES = ["@menapo/vi18n", "@menapo/vi18n/server"];
8
+ /** Valid range of `ids.length`. */
9
+ const ID_LENGTH = {
10
+ min: 8,
11
+ max: 16,
12
+ default: 12
13
+ };
14
+ /**
15
+ * Defaults (PLAN §5.7). Relative paths here are resolved against the config
16
+ * directory; `catalogs.path` becomes `locales/{locale}.json` when only
17
+ * `format: "json"` is given.
18
+ */
19
+ const DEFAULT_CONFIG = {
20
+ sourceLocale: "en",
21
+ locales: ["en"],
22
+ pseudoLocales: [],
23
+ fallbacks: {},
24
+ project: {
25
+ include: ["src"],
26
+ extensions: [
27
+ ".js",
28
+ ".jsx",
29
+ ".mjs",
30
+ ".ts",
31
+ ".tsx",
32
+ ".mts",
33
+ ".svelte",
34
+ ".vue",
35
+ ".astro",
36
+ ".mdx"
37
+ ],
38
+ exclude: [
39
+ "node_modules",
40
+ "/dist",
41
+ "/build",
42
+ "**/*.test.*",
43
+ "**/*.spec.*",
44
+ "**/__tests__/**"
45
+ ]
46
+ },
47
+ extraction: {
48
+ importSources: [...DEFAULT_IMPORT_SOURCES],
49
+ aliases: [],
50
+ globals: [],
51
+ keep: [],
52
+ dependencies: [],
53
+ repeatedText: 3
54
+ },
55
+ ids: { length: ID_LENGTH.default },
56
+ catalogs: {
57
+ format: "po",
58
+ path: "locales/{locale}.po",
59
+ msgid: "source",
60
+ icuFlag: false
61
+ },
62
+ output: {
63
+ split: {
64
+ shared: "per-set",
65
+ dupBelow: 1024,
66
+ minBytes: 1024,
67
+ maxBundlesPerRoot: null
68
+ },
69
+ guard: "auto",
70
+ manifestPath: "vi18n/{locale}/manifest.json",
71
+ manifest: "data",
72
+ baseEntries: [],
73
+ compactIds: false,
74
+ perLocale: false
75
+ },
76
+ routing: {
77
+ strategy: [
78
+ "url",
79
+ "cookie",
80
+ "header",
81
+ "default"
82
+ ],
83
+ routeStrategies: {},
84
+ url: "prefix_except_default",
85
+ redirectRoot: false,
86
+ propagate: "header",
87
+ switch: "in-place",
88
+ cookie: {
89
+ name: "vi18n_locale",
90
+ maxAge: 31536e3
91
+ },
92
+ base: null,
93
+ paths: {},
94
+ domains: {}
95
+ },
96
+ ssr: {
97
+ timeZone: "UTC",
98
+ timeZoneFrom: {},
99
+ payload: "bundles",
100
+ catalogs: "auto",
101
+ maxLoadedLocales: 8,
102
+ normalizeSpaces: true
103
+ },
104
+ ai: {
105
+ provider: "gemini",
106
+ model: "gemini-3.8-flash",
107
+ exclude: [],
108
+ glossary: {},
109
+ doNotTranslate: [],
110
+ tone: {},
111
+ description: null,
112
+ apiKeyEnv: "GEMINI_API_KEY",
113
+ batchSize: 60,
114
+ concurrency: 4,
115
+ dev: false
116
+ },
117
+ defaults: { tags: {} },
118
+ devtools: false,
119
+ strict: {
120
+ missing: "warn",
121
+ invalid: "error",
122
+ moduleScope: "warn"
123
+ }
124
+ };
125
+ // src/core/ir/pseudo.ts
2
126
  /**
3
127
  * Accented look-alikes of `A–Z` then `a–z` (one precomposed code point each),
4
128
  * readable at a glance yet impossible to mistake for untranslated text.
@@ -141,5 +265,4 @@ function wrap(nodes, open, close) {
141
265
  });
142
266
  return nodes;
143
267
  }
144
- //#endregion
145
- export { pseudoLocalize as t };
268
+ export { ID_LENGTH as a, DEFAULT_IMPORT_SOURCES as i, CONFIG_FILE as n, PSEUDO_LOCALES as o, DEFAULT_CONFIG as r, pseudoLocalize as t };