@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
|
@@ -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-BfSOBeBd.js";
|
|
2
|
+
import { f as createCodec, h as isManualId, r as validateTranslation } from "./validate-zv4-IZyZ.js";
|
|
3
|
+
import { r as loadConfig } from "./load-BFLLqY8x.js";
|
|
4
|
+
import { n as isDiagnosticError } from "./diagnostics-1onDF6Ua.js";
|
|
5
|
+
import { i as genFileUpToDate, n as syncCatalogs, r as GEN_FILE, s as scanProject } from "./sync-CpL0Qsgw.js";
|
|
6
|
+
import { i as rootRelative, o as errorMessage, r as plural } from "./output-CF9uvk_-.js";
|
|
7
|
+
import { r as resolveDuplicates, t as duplicateDiagnostics } from "./duplicates-CsUXRX2J.js";
|
|
8
|
+
import { r as EXIT } from "./types-Ds_vebja.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-DFKSGVE9.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,127 @@
|
|
|
1
|
-
|
|
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
|
+
},
|
|
54
|
+
ids: { length: ID_LENGTH.default },
|
|
55
|
+
catalogs: {
|
|
56
|
+
format: "po",
|
|
57
|
+
path: "locales/{locale}.po",
|
|
58
|
+
msgid: "source",
|
|
59
|
+
icuFlag: false
|
|
60
|
+
},
|
|
61
|
+
output: {
|
|
62
|
+
split: {
|
|
63
|
+
shared: "per-set",
|
|
64
|
+
dupBelow: 1024,
|
|
65
|
+
minBytes: 1024,
|
|
66
|
+
maxBundlesPerRoot: null
|
|
67
|
+
},
|
|
68
|
+
guard: "auto",
|
|
69
|
+
manifestPath: "vi18n/{locale}/manifest.json",
|
|
70
|
+
manifest: "data",
|
|
71
|
+
baseEntries: [],
|
|
72
|
+
compactIds: false,
|
|
73
|
+
perLocale: false
|
|
74
|
+
},
|
|
75
|
+
routing: {
|
|
76
|
+
strategy: [
|
|
77
|
+
"url",
|
|
78
|
+
"cookie",
|
|
79
|
+
"header",
|
|
80
|
+
"default"
|
|
81
|
+
],
|
|
82
|
+
routeStrategies: {},
|
|
83
|
+
url: "prefix_except_default",
|
|
84
|
+
redirectRoot: false,
|
|
85
|
+
propagate: "header",
|
|
86
|
+
switch: "in-place",
|
|
87
|
+
cookie: {
|
|
88
|
+
name: "vi18n_locale",
|
|
89
|
+
maxAge: 31536e3
|
|
90
|
+
},
|
|
91
|
+
base: null,
|
|
92
|
+
paths: {},
|
|
93
|
+
domains: {}
|
|
94
|
+
},
|
|
95
|
+
ssr: {
|
|
96
|
+
timeZone: "UTC",
|
|
97
|
+
timeZoneFrom: {},
|
|
98
|
+
payload: "bundles",
|
|
99
|
+
catalogs: "auto",
|
|
100
|
+
maxLoadedLocales: 8,
|
|
101
|
+
normalizeSpaces: true
|
|
102
|
+
},
|
|
103
|
+
ai: {
|
|
104
|
+
provider: "gemini",
|
|
105
|
+
model: "gemini-3.8-flash",
|
|
106
|
+
exclude: [],
|
|
107
|
+
glossary: {},
|
|
108
|
+
doNotTranslate: [],
|
|
109
|
+
tone: {},
|
|
110
|
+
description: null,
|
|
111
|
+
apiKeyEnv: "GEMINI_API_KEY",
|
|
112
|
+
batchSize: 60,
|
|
113
|
+
concurrency: 4,
|
|
114
|
+
dev: false
|
|
115
|
+
},
|
|
116
|
+
defaults: { tags: {} },
|
|
117
|
+
devtools: false,
|
|
118
|
+
strict: {
|
|
119
|
+
missing: "warn",
|
|
120
|
+
invalid: "error",
|
|
121
|
+
moduleScope: "warn"
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
// src/core/ir/pseudo.ts
|
|
2
125
|
/**
|
|
3
126
|
* Accented look-alikes of `A–Z` then `a–z` (one precomposed code point each),
|
|
4
127
|
* readable at a glance yet impossible to mistake for untranslated text.
|
|
@@ -141,5 +264,4 @@ function wrap(nodes, open, close) {
|
|
|
141
264
|
});
|
|
142
265
|
return nodes;
|
|
143
266
|
}
|
|
144
|
-
|
|
145
|
-
export { pseudoLocalize as t };
|
|
267
|
+
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 };
|