@menapo/vi18n 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/{apply-Bre-lY9J.js → apply-Bg-3rB2m.js} +69 -89
- package/dist/{captured-Bj8bO6vd.js → captured-DfLk50Ji.js} +196 -217
- package/dist/{check-BIKEuu6B.js → check-CunekuYs.js} +76 -85
- package/dist/cli.js +2 -3
- package/dist/{collect-Cx4_SKOe.js → collect-CYATDjdo.js} +1 -2
- package/dist/collisions-CDSdtLQm.js +215 -0
- package/dist/{compile-Cc97JaW2.js → compile-DqkofbiO.js} +376 -331
- package/dist/compile-hva0qjhZ.js +240 -0
- package/dist/concurrency-BCY_4zcr.js +1 -0
- package/dist/concurrency-Dy2ny50V.js +107 -0
- package/dist/config.d.ts +1 -5
- package/dist/config.js +4 -5
- package/dist/{types-D3QGM8XO.js → diagnostics-LgIWyeSp.js} +28 -27
- package/dist/{dir-zw6bGMKQ.js → dir-TGLYuOZb.js} +34 -37
- package/dist/{duplicates-yuRljQ6h.js → duplicates-8cudcHNj.js} +10 -27
- package/dist/engine-ecRD8-IE.js +556 -0
- package/dist/engine.d.ts +1 -5
- package/dist/engine.js +297 -168
- package/dist/exchange-DjwlrTQ9.js +41 -0
- package/dist/{exclude-Du-Zd_qI.js → exclude-BFETmvde.js} +2 -3
- package/dist/{export-C9Sy6UWv.js → export-D2tsqWIr.js} +17 -38
- package/dist/{extract-C3S8btx0.js → extract-BxYchVmY.js} +114 -82
- package/dist/{formats-9unqj_fZ.js → formats-BaryZ2N7.js} +352 -276
- package/dist/fs-ezCMZeDV.js +52 -0
- package/dist/i18next-COO6o0tX.js +1907 -0
- package/dist/i18next-Dr7DCQlQ.js +1 -0
- package/dist/{import-nANvQutw.js → import-vSC29Cn4.js} +81 -75
- package/dist/index.d.ts +1 -13
- package/dist/index.js +14 -16
- package/dist/{init-C2ScuW6a.js → init-Cc7A-8VX.js} +466 -501
- package/dist/{library-D5CWvTQs.js → library-tp_xqzSY.js} +975 -451
- package/dist/lingui-BnnlqGXT.js +902 -0
- package/dist/lint.d.ts +0 -4
- package/dist/lint.js +70 -82
- package/dist/{load-gW-oJt1Q.js → load-BSIeGJ5v.js} +275 -148
- package/dist/{load-CQRz4PpM.js → load-SSrAeJVB.js} +1214 -1116
- package/dist/{locales-DX4MOBFE.js → locales-D0U-yVRm.js} +271 -237
- package/dist/{lsp-RMMMc88P.js → lsp-DvC11pBZ.js} +4 -5
- package/dist/{match-BGr8EXB3.js → match-BLDcj610.js} +11 -4
- package/dist/{mcp-CHVwBoRP.js → mcp-D2zzOTBy.js} +4 -5
- package/dist/{merge-driver-BTX87aVm.js → merge-driver-BLI8OtAc.js} +138 -122
- package/dist/migrate-1r43OBfe.js +1 -0
- package/dist/migrate-ChDGhlC-.js +2169 -0
- package/dist/{openai-CTaMDcl-.js → openai-CLn4puY8.js} +128 -87
- package/dist/{output-DWE3SIUA.js → output-D5tAt8q4.js} +15 -9
- package/dist/parse.d.ts +1 -3
- package/dist/parse.js +7 -8
- package/dist/{pipeline-C9Dbotkh.js → pipeline-BJSkkRYC.js} +387 -359
- package/dist/{pipeline-DbX6rlo5.js → pipeline-BeCc441z.js} +1 -1
- package/dist/project-B5KIO0q-.js +544 -0
- package/dist/{pseudo-DRv30iN5.js → pseudo-B2DUpoLu.js} +126 -3
- package/dist/{raw-C4Y6vyGY.js → raw-YsYZMS9n.js} +52 -29
- package/dist/react-intl-C8JehBBL.js +634 -0
- package/dist/rename-ZVGq9ZG1.js +577 -0
- package/dist/repeated-uuI1tUGg.js +85 -0
- package/dist/restore-xlBIrtRt.js +199 -0
- package/dist/rewrite-BwzXoBiA.js +415 -0
- package/dist/{rich-DCUKl5HM.js → rich-ApY1Dm4S.js} +35 -28
- package/dist/rolldown-runtime-C1I3wEg2.js +43 -0
- package/dist/{rolldown-runtime-D7D4PA-g.js → rolldown-runtime-D8jQpDG7.js} +1 -2
- package/dist/run-CQ9pDLSa.js +674 -0
- package/dist/scan-worker.d.ts +2 -4
- package/dist/scan-worker.js +1 -1
- package/dist/{scoped-BMYpSthj.js → scoped-h3KE8XWW.js} +3 -4
- package/dist/{server-Da1Ot9IN.js → server-Br8tAuG2.js} +312 -386
- package/dist/{server-deBOq2vq.js → server-DJRpUQVZ.js} +1059 -333
- package/dist/server.d.ts +1 -17
- package/dist/server.js +419 -379
- package/dist/{sitemap-DJXzKoza.js → sitemap-CSAkm6oi.js} +21 -33
- package/dist/{sources-D19czDSA.js → sources-DNVbYsgs.js} +713 -373
- package/dist/{status-zr4jY59Y.js → status-q6M3rBrh.js} +30 -30
- package/dist/{stdio-FPOKQAgu.js → stdio-D9kTzyqB.js} +2 -4
- package/dist/{stdio-CVaJfxA7.js → stdio-FWIVU3P4.js} +1 -2
- package/dist/sync-BNIAwMhR.js +1352 -0
- package/dist/{t-DC-c9zE5.js → t-gvEXx25s.js} +76 -53
- package/dist/test.d.ts +5 -16
- package/dist/test.js +126 -56
- package/dist/translate-BP4iVhOR.js +336 -0
- package/dist/{ts-BaU5yOf0.js → ts-BX6kwig5.js} +25 -14
- package/dist/{types-DtvQ7UdD.js → types-3kwyaCAm.js} +1 -2
- package/dist/{types-DsdWBG0b.d.ts → types-B4wNX6PA.d.ts} +6 -8
- package/dist/{types-CgUCkFU1.d.ts → types-_4UdFhR9.d.ts} +24 -21
- package/dist/types-xR2exI3L.js +42 -0
- package/dist/{units-CQ5Q99RC.js → units-DPPfCN7j.js} +7 -16
- package/dist/{url-CRfCOhUI.js → url-Bpc6wLea.js} +24 -11
- package/dist/{url-CsBkRaJy.js → url-D2_VlEeH.js} +25 -12
- package/dist/{validate-BxpupdAf.js → validate-CgzaDdOY.js} +690 -377
- package/dist/{validate-D6DJepZv.js → validate-PGgMsasz.js} +3 -5
- package/dist/{version-Byqi2guX.js → version-DC-J5WvV.js} +3 -5
- package/dist/{vite-scan-CT_vsp4g.js → vite-scan-kM8Ta3rO.js} +87 -92
- package/dist/vite.d.ts +2 -6
- package/dist/vite.js +6500 -6032
- package/dist/vue-i18n-_uIXlFVh.js +806 -0
- package/dist/{which-BOemZ5Q8.js → which-DFWk_KwN.js} +44 -37
- package/dist/{worker-84U6uYB3.js → worker-zlhNj4y3.js} +454 -608
- package/package.json +5 -5
- package/dist/check-HsmmpJZg.js +0 -1
- package/dist/codec-DuvU2VQy.js +0 -207
- package/dist/collisions-CfpZU8e4.js +0 -217
- package/dist/compile-BaDh0cHG.js +0 -245
- package/dist/concurrency-C9UUWuDC.js +0 -96
- package/dist/concurrency-DONL7t4V.js +0 -1
- package/dist/engine-C2ENBRJe.js +0 -531
- package/dist/i18next-9HAoxwUI.js +0 -1
- package/dist/i18next-BEJgv_S8.js +0 -1596
- package/dist/lingui-zUiCl9Um.js +0 -833
- package/dist/messages-BfjIExyB.js +0 -166
- package/dist/migrate-IpLDMXmq.js +0 -1484
- package/dist/migrate-rCQuOGsf.js +0 -1
- package/dist/project-Bw9UPIdx.js +0 -1046
- package/dist/project-C4GpaN-n.js +0 -381
- package/dist/react-intl-BP0u-D5m.js +0 -519
- package/dist/restore-CiYv-jxS.js +0 -175
- package/dist/rewrite-EsIw_lsq.js +0 -803
- package/dist/run-BEcnBbu-.js +0 -694
- package/dist/runtime-DTMmliT1.js +0 -64
- package/dist/sync-B9V2KFwb.js +0 -658
- package/dist/translate-CQnJfLjO.js +0 -299
- package/dist/types-wSh9fCBY.js +0 -11
- package/dist/vue-i18n-g0iGy6CZ.js +0 -651
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
import { i as DEFAULT_CONFIG, n as isDiagnosticError } from "./diagnostics-LgIWyeSp.js";
|
|
2
|
+
import { t as VERSION } from "./version-DC-J5WvV.js";
|
|
3
|
+
import { t as PROVIDER_PRESETS } from "./openai-CLn4puY8.js";
|
|
4
|
+
import { t as EXCHANGE_FORMATS } from "./units-DPPfCN7j.js";
|
|
5
|
+
import { a as MIGRATIONS, i as LIBRARIES, n as COMMAND_NAMES, r as EXIT, t as CHECK_CATEGORIES } from "./types-xR2exI3L.js";
|
|
6
|
+
import { n as createOutput, o as errorMessage } from "./output-D5tAt8q4.js";
|
|
7
|
+
import { t as CliExit } from "./project-B5KIO0q-.js";
|
|
8
|
+
import { resolve } from "node:path";
|
|
9
|
+
import { parseArgs } from "node:util";
|
|
10
|
+
// src/cli/args.ts
|
|
11
|
+
/**
|
|
12
|
+
* Command-line parsing (INTERNALS §2.14): `node:util` `parseArgs`, strict, so
|
|
13
|
+
* an unknown flag or a stray positional is a usage error (exit 2) instead of
|
|
14
|
+
* a silently different run. Global flags may appear before or after the
|
|
15
|
+
* command name.
|
|
16
|
+
*/
|
|
17
|
+
const COMMANDS = COMMAND_NAMES;
|
|
18
|
+
const TIERS = [
|
|
19
|
+
"standard",
|
|
20
|
+
"flex",
|
|
21
|
+
"batch"
|
|
22
|
+
];
|
|
23
|
+
const GLOBAL = {
|
|
24
|
+
config: { type: "string" },
|
|
25
|
+
json: { type: "boolean" },
|
|
26
|
+
cwd: { type: "string" },
|
|
27
|
+
help: {
|
|
28
|
+
type: "boolean",
|
|
29
|
+
short: "h"
|
|
30
|
+
},
|
|
31
|
+
version: {
|
|
32
|
+
type: "boolean",
|
|
33
|
+
short: "v"
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/** Thrown inside flag conversion; becomes a `usage` result. */
|
|
37
|
+
var UsageError = class extends Error {};
|
|
38
|
+
function isCommand(name) {
|
|
39
|
+
return COMMANDS.includes(name);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The command is the first token that is neither a flag nor the value of a
|
|
43
|
+
* global flag that takes one (`--config x`, `--cwd x`), so `vi18n --cwd app
|
|
44
|
+
* extract` and `vi18n extract --cwd app` mean the same.
|
|
45
|
+
*/
|
|
46
|
+
function findCommand(argv) {
|
|
47
|
+
for (let i = 0; i < argv.length; i++) {
|
|
48
|
+
const token = argv[i];
|
|
49
|
+
if (token === "--") return null;
|
|
50
|
+
if (token === "--config" || token === "--cwd") {
|
|
51
|
+
i++;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (!token.startsWith("-")) return {
|
|
55
|
+
index: i,
|
|
56
|
+
name: token
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
/** Only global flags: `--help`, `--version`, or nothing to do. */
|
|
62
|
+
function parseWithoutCommand(argv, json) {
|
|
63
|
+
const rest = tryParse(argv, GLOBAL, false);
|
|
64
|
+
if ("error" in rest) return {
|
|
65
|
+
kind: "usage",
|
|
66
|
+
command: null,
|
|
67
|
+
message: rest.error,
|
|
68
|
+
json
|
|
69
|
+
};
|
|
70
|
+
if (rest.values.version === true) return {
|
|
71
|
+
kind: "version",
|
|
72
|
+
command: null,
|
|
73
|
+
json
|
|
74
|
+
};
|
|
75
|
+
if (rest.values.help === true) return {
|
|
76
|
+
kind: "help",
|
|
77
|
+
command: null,
|
|
78
|
+
json
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
kind: "usage",
|
|
82
|
+
command: null,
|
|
83
|
+
message: `missing command; expected one of ${COMMANDS.join(", ")}`,
|
|
84
|
+
json
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function parseCommandLine(argv, cwd) {
|
|
88
|
+
const found = findCommand(argv);
|
|
89
|
+
const json = argv.includes("--json");
|
|
90
|
+
if (found === null) return parseWithoutCommand(argv, json);
|
|
91
|
+
if (!isCommand(found.name)) return {
|
|
92
|
+
kind: "usage",
|
|
93
|
+
command: null,
|
|
94
|
+
message: `unknown command "${found.name}"; expected one of ${COMMANDS.join(", ")}`,
|
|
95
|
+
json
|
|
96
|
+
};
|
|
97
|
+
const command = found.name;
|
|
98
|
+
const spec = SPECS[command];
|
|
99
|
+
const parsed = tryParse([...argv.slice(0, found.index), ...argv.slice(found.index + 1)], {
|
|
100
|
+
...GLOBAL,
|
|
101
|
+
...spec.options
|
|
102
|
+
}, spec.positional === true);
|
|
103
|
+
if ("error" in parsed) return {
|
|
104
|
+
kind: "usage",
|
|
105
|
+
command,
|
|
106
|
+
message: parsed.error,
|
|
107
|
+
json
|
|
108
|
+
};
|
|
109
|
+
const { values, positionals } = parsed;
|
|
110
|
+
if (values.version === true) return {
|
|
111
|
+
kind: "version",
|
|
112
|
+
command,
|
|
113
|
+
json
|
|
114
|
+
};
|
|
115
|
+
if (values.help === true) return {
|
|
116
|
+
kind: "help",
|
|
117
|
+
command,
|
|
118
|
+
json
|
|
119
|
+
};
|
|
120
|
+
const global = {
|
|
121
|
+
config: str(values.config),
|
|
122
|
+
json: values.json === true,
|
|
123
|
+
cwd: resolve(cwd, str(values.cwd) ?? ".")
|
|
124
|
+
};
|
|
125
|
+
try {
|
|
126
|
+
const run = runCommand$1(command, {
|
|
127
|
+
values,
|
|
128
|
+
positionals,
|
|
129
|
+
global
|
|
130
|
+
});
|
|
131
|
+
if (run.command === "check" && run.flags.format === "json") return {
|
|
132
|
+
...run,
|
|
133
|
+
global: {
|
|
134
|
+
...global,
|
|
135
|
+
json: true
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
return run;
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (error instanceof UsageError) return {
|
|
141
|
+
kind: "usage",
|
|
142
|
+
command,
|
|
143
|
+
message: error.message,
|
|
144
|
+
json: global.json
|
|
145
|
+
};
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function runCommand$1(command, input) {
|
|
150
|
+
const spec = SPECS[command];
|
|
151
|
+
return {
|
|
152
|
+
kind: "run",
|
|
153
|
+
command,
|
|
154
|
+
global: input.global,
|
|
155
|
+
flags: spec.flags(input)
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function tryParse(args, options, allowPositionals) {
|
|
159
|
+
try {
|
|
160
|
+
const { values, positionals } = parseArgs({
|
|
161
|
+
args: [...args],
|
|
162
|
+
options,
|
|
163
|
+
strict: true,
|
|
164
|
+
allowPositionals
|
|
165
|
+
});
|
|
166
|
+
return {
|
|
167
|
+
values,
|
|
168
|
+
positionals
|
|
169
|
+
};
|
|
170
|
+
} catch (error) {
|
|
171
|
+
return { error: errorMessage(error) };
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function str(value) {
|
|
175
|
+
return typeof value === "string" ? value : null;
|
|
176
|
+
}
|
|
177
|
+
function bool(value) {
|
|
178
|
+
return value === true;
|
|
179
|
+
}
|
|
180
|
+
function list(value) {
|
|
181
|
+
if (!Array.isArray(value)) return [];
|
|
182
|
+
return value.filter((item) => typeof item === "string");
|
|
183
|
+
}
|
|
184
|
+
function oneOf(flag, value, allowed) {
|
|
185
|
+
if (value === null) return null;
|
|
186
|
+
if (allowed.includes(value)) return value;
|
|
187
|
+
throw new UsageError(`--${flag} must be one of ${allowed.join(", ")}, not "${value}"`);
|
|
188
|
+
}
|
|
189
|
+
function initFlags({ values }) {
|
|
190
|
+
const locales = (str(values.locales) ?? "").split(",").map((locale) => locale.trim()).filter((locale) => locale !== "");
|
|
191
|
+
return {
|
|
192
|
+
yes: bool(values.yes),
|
|
193
|
+
format: oneOf("format", str(values.format), ["po", "json"]),
|
|
194
|
+
locales,
|
|
195
|
+
sourceLocale: str(values["source-locale"]),
|
|
196
|
+
rich: bool(values.rich)
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function extractFlags({ values }) {
|
|
200
|
+
const flags = {
|
|
201
|
+
check: bool(values.check),
|
|
202
|
+
watch: bool(values.watch),
|
|
203
|
+
yes: bool(values.yes),
|
|
204
|
+
vite: bool(values.vite)
|
|
205
|
+
};
|
|
206
|
+
if (flags.check && flags.watch) throw new UsageError("--check and --watch cannot be combined");
|
|
207
|
+
if (flags.vite && flags.watch) throw new UsageError("--vite and --watch cannot be combined; vite dev keeps the catalogs current");
|
|
208
|
+
return flags;
|
|
209
|
+
}
|
|
210
|
+
function checkFlags({ values, positionals, global }) {
|
|
211
|
+
const categories = [];
|
|
212
|
+
for (const positional of positionals) {
|
|
213
|
+
const category = oneOf("category", positional, CHECK_CATEGORIES);
|
|
214
|
+
if (category !== null && !categories.includes(category)) categories.push(category);
|
|
215
|
+
}
|
|
216
|
+
const format = oneOf("format", str(values.format), [
|
|
217
|
+
"text",
|
|
218
|
+
"github",
|
|
219
|
+
"json"
|
|
220
|
+
]) ?? "text";
|
|
221
|
+
return {
|
|
222
|
+
categories,
|
|
223
|
+
ci: bool(values.ci),
|
|
224
|
+
format: global.json ? "json" : format
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
function compileFlags({ values }) {
|
|
228
|
+
const flags = {
|
|
229
|
+
out: str(values.out),
|
|
230
|
+
assets: str(values.assets),
|
|
231
|
+
strict: bool(values.strict),
|
|
232
|
+
pseudo: bool(values.pseudo),
|
|
233
|
+
check: bool(values.check)
|
|
234
|
+
};
|
|
235
|
+
if (flags.check && flags.out === null) throw new UsageError("--check needs --out <dir>: the directory to compare");
|
|
236
|
+
if (flags.assets !== null && flags.out === null) throw new UsageError("--assets needs --out <dir>: the directory for config.json, sources.json and catalogs.js");
|
|
237
|
+
return flags;
|
|
238
|
+
}
|
|
239
|
+
function maxCostFlag(raw) {
|
|
240
|
+
if (raw === null) return null;
|
|
241
|
+
const maxCost = raw.trim() === "" ? NaN : Number(raw);
|
|
242
|
+
if (!Number.isFinite(maxCost) || maxCost < 0) throw new UsageError(`--max-cost must be a non-negative number of USD, not "${raw}"`);
|
|
243
|
+
return maxCost;
|
|
244
|
+
}
|
|
245
|
+
function translateFlags({ values }) {
|
|
246
|
+
const provider = oneOf("provider", str(values.provider), PROVIDER_PRESETS);
|
|
247
|
+
const model = str(values.model);
|
|
248
|
+
if (provider !== null && provider !== "gemini" && model === null) throw new UsageError(`--provider ${provider} needs --model <id>`);
|
|
249
|
+
const maxCost = maxCostFlag(str(values["max-cost"]));
|
|
250
|
+
return {
|
|
251
|
+
locales: list(values.locale),
|
|
252
|
+
model,
|
|
253
|
+
retranslate: oneOf("retranslate", str(values.retranslate), ["ai", "all"]),
|
|
254
|
+
provider,
|
|
255
|
+
tier: oneOf("tier", str(values.tier), TIERS) ?? "standard",
|
|
256
|
+
dryRun: bool(values["dry-run"]),
|
|
257
|
+
maxCost
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function catalogFlag(raw) {
|
|
261
|
+
const eq = raw.indexOf("=");
|
|
262
|
+
if (eq === -1) return {
|
|
263
|
+
locale: null,
|
|
264
|
+
file: raw
|
|
265
|
+
};
|
|
266
|
+
const locale = raw.slice(0, eq).trim();
|
|
267
|
+
const file = raw.slice(eq + 1).trim();
|
|
268
|
+
if (locale === "" || file === "") throw new UsageError(`--catalog ${raw}: expected <file> or <locale>=<file>`);
|
|
269
|
+
return {
|
|
270
|
+
locale,
|
|
271
|
+
file
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
/** saas-i18n reads one key catalogue per locale, the default locale's first. */
|
|
275
|
+
function checkSaasCatalogs(catalogs, keepIds) {
|
|
276
|
+
if (keepIds) throw new UsageError("--keep-ids is for the libraries: saas-i18n keys always become manual ids");
|
|
277
|
+
if (catalogs.length === 0) throw new UsageError("--catalog <file> is required: the default locale's key catalogue");
|
|
278
|
+
for (const entry of catalogs.slice(1)) if (entry.locale === null) throw new UsageError(`--catalog ${entry.file}: only the first --catalog may omit the locale (<locale>=<file>)`);
|
|
279
|
+
}
|
|
280
|
+
function migrateFlags({ values }) {
|
|
281
|
+
const from = oneOf("from", str(values.from), MIGRATIONS);
|
|
282
|
+
if (from === null) throw new UsageError(`--from is required (${MIGRATIONS.join(", ")})`);
|
|
283
|
+
const catalogs = list(values.catalog).map(catalogFlag);
|
|
284
|
+
const keepIds = bool(values["keep-ids"]);
|
|
285
|
+
if (from === "saas-i18n") checkSaasCatalogs(catalogs, keepIds);
|
|
286
|
+
return {
|
|
287
|
+
from,
|
|
288
|
+
catalogs,
|
|
289
|
+
keepIds,
|
|
290
|
+
write: bool(values.write)
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
function sitemapFlags({ values, positionals }) {
|
|
294
|
+
const flags = {
|
|
295
|
+
routes: positionals,
|
|
296
|
+
routesFile: str(values.routes),
|
|
297
|
+
baseUrl: str(values["base-url"]),
|
|
298
|
+
out: str(values.out),
|
|
299
|
+
check: bool(values.check)
|
|
300
|
+
};
|
|
301
|
+
if (flags.check && flags.out === null) throw new UsageError("--check needs --out <file>: the sitemap to compare");
|
|
302
|
+
return flags;
|
|
303
|
+
}
|
|
304
|
+
function exportFlags({ values }) {
|
|
305
|
+
const format = oneOf("format", str(values.format), EXCHANGE_FORMATS);
|
|
306
|
+
if (format === null) throw new UsageError(`--format is required: one of ${EXCHANGE_FORMATS.join(", ")}`);
|
|
307
|
+
return {
|
|
308
|
+
format,
|
|
309
|
+
locales: list(values.locale),
|
|
310
|
+
out: str(values.out),
|
|
311
|
+
missing: bool(values.missing),
|
|
312
|
+
ai: bool(values.ai)
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
function importFlags({ values, positionals }) {
|
|
316
|
+
if (positionals.length === 0) throw new UsageError("name the file(s) to import");
|
|
317
|
+
const flags = {
|
|
318
|
+
format: oneOf("format", str(values.format), EXCHANGE_FORMATS),
|
|
319
|
+
locale: str(values.locale),
|
|
320
|
+
dryRun: bool(values["dry-run"]),
|
|
321
|
+
files: positionals
|
|
322
|
+
};
|
|
323
|
+
if (flags.locale !== null && positionals.length > 1) throw new UsageError("--locale applies to one file; import the others separately");
|
|
324
|
+
return flags;
|
|
325
|
+
}
|
|
326
|
+
function restoreFlags({ values }) {
|
|
327
|
+
const from = str(values.from);
|
|
328
|
+
if (from === null || from.trim() === "") throw new UsageError("--from <git-rev> is required: the revision to restore from");
|
|
329
|
+
if (from.startsWith("-")) throw new UsageError(`--from ${from}: not a revision`);
|
|
330
|
+
return {
|
|
331
|
+
from,
|
|
332
|
+
locales: list(values.locale),
|
|
333
|
+
dryRun: bool(values["dry-run"])
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
function renameFlags({ values, positionals }) {
|
|
337
|
+
if (positionals.length !== 2) throw new UsageError("expected <old> <new>: the text as written in the code, then the text it becomes (quote each: vi18n rename \"Sign in\" \"Log in\")");
|
|
338
|
+
const [from, to] = positionals;
|
|
339
|
+
if (from === to) throw new UsageError("<new> is the same text as <old>; there is nothing to rename");
|
|
340
|
+
return {
|
|
341
|
+
from,
|
|
342
|
+
to,
|
|
343
|
+
write: bool(values.write),
|
|
344
|
+
review: bool(values.review),
|
|
345
|
+
merge: bool(values.merge)
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
function whichFlags({ positionals }) {
|
|
349
|
+
const query = positionals.join(" ");
|
|
350
|
+
if (query.trim() === "") throw new UsageError("name an id, the start of one, or source text");
|
|
351
|
+
return { query };
|
|
352
|
+
}
|
|
353
|
+
function mergeDriverFlags({ positionals }) {
|
|
354
|
+
if (positionals.length < 3 || positionals.length > 4) throw new UsageError("expected <base> <ours> <theirs> [<path>], as git passes %O %A %B %P");
|
|
355
|
+
const [base, ours, theirs, path] = positionals;
|
|
356
|
+
return {
|
|
357
|
+
base,
|
|
358
|
+
ours,
|
|
359
|
+
theirs,
|
|
360
|
+
path: path ?? null
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
/** `lsp` and `mcp`: stdout carries the protocol, so it cannot also carry an envelope. */
|
|
364
|
+
function protocolFlags(command) {
|
|
365
|
+
return ({ global }) => {
|
|
366
|
+
if (global.json) throw new UsageError(`--json does not apply: vi18n ${command} speaks its protocol on stdio`);
|
|
367
|
+
return {};
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
const SPECS = {
|
|
371
|
+
init: {
|
|
372
|
+
options: {
|
|
373
|
+
yes: {
|
|
374
|
+
type: "boolean",
|
|
375
|
+
short: "y"
|
|
376
|
+
},
|
|
377
|
+
format: { type: "string" },
|
|
378
|
+
locales: { type: "string" },
|
|
379
|
+
"source-locale": { type: "string" },
|
|
380
|
+
rich: { type: "boolean" }
|
|
381
|
+
},
|
|
382
|
+
flags: initFlags
|
|
383
|
+
},
|
|
384
|
+
extract: {
|
|
385
|
+
options: {
|
|
386
|
+
check: { type: "boolean" },
|
|
387
|
+
watch: { type: "boolean" },
|
|
388
|
+
yes: {
|
|
389
|
+
type: "boolean",
|
|
390
|
+
short: "y"
|
|
391
|
+
},
|
|
392
|
+
vite: { type: "boolean" }
|
|
393
|
+
},
|
|
394
|
+
flags: extractFlags
|
|
395
|
+
},
|
|
396
|
+
check: {
|
|
397
|
+
options: {
|
|
398
|
+
ci: { type: "boolean" },
|
|
399
|
+
format: { type: "string" }
|
|
400
|
+
},
|
|
401
|
+
positional: true,
|
|
402
|
+
flags: checkFlags
|
|
403
|
+
},
|
|
404
|
+
status: {
|
|
405
|
+
options: { locale: {
|
|
406
|
+
type: "string",
|
|
407
|
+
multiple: true
|
|
408
|
+
} },
|
|
409
|
+
flags: ({ values }) => ({ locales: list(values.locale) })
|
|
410
|
+
},
|
|
411
|
+
compile: {
|
|
412
|
+
options: {
|
|
413
|
+
out: { type: "string" },
|
|
414
|
+
assets: { type: "string" },
|
|
415
|
+
strict: { type: "boolean" },
|
|
416
|
+
pseudo: { type: "boolean" },
|
|
417
|
+
check: { type: "boolean" }
|
|
418
|
+
},
|
|
419
|
+
flags: compileFlags
|
|
420
|
+
},
|
|
421
|
+
translate: {
|
|
422
|
+
options: {
|
|
423
|
+
locale: {
|
|
424
|
+
type: "string",
|
|
425
|
+
multiple: true
|
|
426
|
+
},
|
|
427
|
+
model: { type: "string" },
|
|
428
|
+
retranslate: { type: "string" },
|
|
429
|
+
provider: { type: "string" },
|
|
430
|
+
tier: { type: "string" },
|
|
431
|
+
"dry-run": { type: "boolean" },
|
|
432
|
+
"max-cost": { type: "string" }
|
|
433
|
+
},
|
|
434
|
+
flags: translateFlags
|
|
435
|
+
},
|
|
436
|
+
migrate: {
|
|
437
|
+
options: {
|
|
438
|
+
from: { type: "string" },
|
|
439
|
+
catalog: {
|
|
440
|
+
type: "string",
|
|
441
|
+
multiple: true
|
|
442
|
+
},
|
|
443
|
+
"keep-ids": { type: "boolean" },
|
|
444
|
+
write: { type: "boolean" }
|
|
445
|
+
},
|
|
446
|
+
flags: migrateFlags
|
|
447
|
+
},
|
|
448
|
+
sitemap: {
|
|
449
|
+
options: {
|
|
450
|
+
routes: { type: "string" },
|
|
451
|
+
"base-url": { type: "string" },
|
|
452
|
+
out: { type: "string" },
|
|
453
|
+
check: { type: "boolean" }
|
|
454
|
+
},
|
|
455
|
+
positional: true,
|
|
456
|
+
flags: sitemapFlags
|
|
457
|
+
},
|
|
458
|
+
export: {
|
|
459
|
+
options: {
|
|
460
|
+
format: { type: "string" },
|
|
461
|
+
locale: {
|
|
462
|
+
type: "string",
|
|
463
|
+
multiple: true
|
|
464
|
+
},
|
|
465
|
+
out: { type: "string" },
|
|
466
|
+
missing: { type: "boolean" },
|
|
467
|
+
ai: { type: "boolean" }
|
|
468
|
+
},
|
|
469
|
+
flags: exportFlags
|
|
470
|
+
},
|
|
471
|
+
import: {
|
|
472
|
+
options: {
|
|
473
|
+
format: { type: "string" },
|
|
474
|
+
locale: { type: "string" },
|
|
475
|
+
"dry-run": { type: "boolean" }
|
|
476
|
+
},
|
|
477
|
+
positional: true,
|
|
478
|
+
flags: importFlags
|
|
479
|
+
},
|
|
480
|
+
restore: {
|
|
481
|
+
options: {
|
|
482
|
+
from: { type: "string" },
|
|
483
|
+
locale: {
|
|
484
|
+
type: "string",
|
|
485
|
+
multiple: true
|
|
486
|
+
},
|
|
487
|
+
"dry-run": { type: "boolean" }
|
|
488
|
+
},
|
|
489
|
+
flags: restoreFlags
|
|
490
|
+
},
|
|
491
|
+
rename: {
|
|
492
|
+
options: {
|
|
493
|
+
write: { type: "boolean" },
|
|
494
|
+
review: { type: "boolean" },
|
|
495
|
+
merge: { type: "boolean" }
|
|
496
|
+
},
|
|
497
|
+
positional: true,
|
|
498
|
+
flags: renameFlags
|
|
499
|
+
},
|
|
500
|
+
which: {
|
|
501
|
+
options: {},
|
|
502
|
+
positional: true,
|
|
503
|
+
flags: whichFlags
|
|
504
|
+
},
|
|
505
|
+
"merge-driver": {
|
|
506
|
+
options: {},
|
|
507
|
+
positional: true,
|
|
508
|
+
flags: mergeDriverFlags
|
|
509
|
+
},
|
|
510
|
+
lsp: {
|
|
511
|
+
options: {
|
|
512
|
+
stdio: { type: "boolean" },
|
|
513
|
+
clientProcessId: { type: "string" }
|
|
514
|
+
},
|
|
515
|
+
flags: protocolFlags("lsp")
|
|
516
|
+
},
|
|
517
|
+
mcp: {
|
|
518
|
+
options: {},
|
|
519
|
+
flags: protocolFlags("mcp")
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
const GLOBAL_HELP = `Global flags:
|
|
523
|
+
--config <path> vi18n.config.ts to use (default: searched upward from the cwd)
|
|
524
|
+
--cwd <dir> run as if started in <dir>
|
|
525
|
+
--json print one JSON object (the command's result) on stdout
|
|
526
|
+
--help, --version`;
|
|
527
|
+
const COMMAND_HELP = {
|
|
528
|
+
init: `vi18n init [--yes] [--format po|json] [--locales en,de] [--source-locale en] [--rich]
|
|
529
|
+
Write vi18n.config.ts, add the plugin to vite.config.*, create the catalogs and vi18n.gen.ts.
|
|
530
|
+
--rich copies a <T> rich-text component for Vue and Svelte into the project (also when configured).`,
|
|
531
|
+
extract: `vi18n extract [--check] [--watch] [--yes] [--vite]
|
|
532
|
+
Sync the catalogs with the code. --check writes nothing and fails on drift; --watch only adds;
|
|
533
|
+
--yes allows clearing or deleting more translations than the safety limit.
|
|
534
|
+
--vite transforms each file through the project's Vite config and plugins instead of reading it,
|
|
535
|
+
for plugins that change code before vi18n sees it (auto-imports, macros).`,
|
|
536
|
+
check: `vi18n check ${CHECK_CATEGORIES.map((c) => `[${c}]`).join(" ")} [--ci] [--format text|github|json]
|
|
537
|
+
Validate catalogs against the code. --ci fails on warnings of the selected categories too.`,
|
|
538
|
+
status: `vi18n status [--json] [--locale <l>]…
|
|
539
|
+
Translation progress per locale, and per bundle when a build report exists.`,
|
|
540
|
+
compile: `vi18n compile [--out <dir>] [--assets <dir>] [--strict] [--pseudo] [--check]
|
|
541
|
+
Compiled JSON per locale plus sources.json and config.json, for code not built by Vite.
|
|
542
|
+
--assets puts the catalogs into a static-assets directory (vi18n/<version>/<locale>/catalog.json)
|
|
543
|
+
and writes <out>/catalogs.js, which reads them through the Workers ASSETS binding.
|
|
544
|
+
--check writes nothing and fails when a file is out of date.`,
|
|
545
|
+
translate: `vi18n translate [--locale <l>]… [--provider ${PROVIDER_PRESETS.join("|")}] [--model <id>] [--tier ${TIERS.join("|")}] [--retranslate ai|all] [--dry-run] [--max-cost <usd>]
|
|
546
|
+
AI-translate the referenced messages that have no translation.
|
|
547
|
+
--provider overrides ai.provider (all but gemini need --model); --tier flex|batch (Gemini) costs half.`,
|
|
548
|
+
migrate: `vi18n migrate --from ${[...LIBRARIES, "saas-i18n"].join("|")} [--catalog [<locale>=]<file|dir>]… [--keep-ids] [--write]
|
|
549
|
+
Rewrite another library's calls into t()/msg()/rich() and its catalogs into vi18n's;
|
|
550
|
+
prints the plan without --write. --keep-ids keeps every key a developer chose as a manual id.`,
|
|
551
|
+
sitemap: `vi18n sitemap [<route>…] [--routes <file>] [--base-url <url>] [--out <file>] [--check]
|
|
552
|
+
Write sitemap.xml: every route in every locale, with hreflang alternates and x-default.
|
|
553
|
+
--base-url is the site's origin and base path (not needed when routing.domains has every locale);
|
|
554
|
+
--routes reads route paths from a file; without --out the sitemap goes to stdout.`,
|
|
555
|
+
export: `vi18n export --format ${EXCHANGE_FORMATS.join("|")} [--locale <l>]… [--out <dir>] [--missing] [--ai]
|
|
556
|
+
Write each locale's catalog in an exchange format for a TMS or translators. --missing keeps the
|
|
557
|
+
entries without a translation that would ship, --ai the AI translations; without --out, one
|
|
558
|
+
locale goes to stdout.`,
|
|
559
|
+
import: `vi18n import [--format ${EXCHANGE_FORMATS.join("|")}] [--locale <l>] [--dry-run] <file>…
|
|
560
|
+
Take translations from exchange files into the catalogs, only where the row's source is the
|
|
561
|
+
entry's exact source; reports what changed and what was skipped. --dry-run writes nothing.`,
|
|
562
|
+
restore: `vi18n restore --from <git-rev> [--locale <l>]… [--dry-run]
|
|
563
|
+
Fill empty entries from that revision's catalogs by exact source text or manual id.`,
|
|
564
|
+
rename: `vi18n rename <old> <new> [--write] [--review] [--merge]
|
|
565
|
+
Change a text at every call site and in every catalog, keeping its translations. <old> is the
|
|
566
|
+
text as written in the code; every t(), msg() and rich() with that text changes, a manual id
|
|
567
|
+
stays. Prints the plan; --write applies it (all files or none). --review marks the carried
|
|
568
|
+
translations fuzzy; --merge lets <new> be a message the code already has.`,
|
|
569
|
+
which: `vi18n which <id|prefix|text>
|
|
570
|
+
Print a message's id, source text, call sites and catalog entries.`,
|
|
571
|
+
"merge-driver": `vi18n merge-driver <base> <ours> <theirs> [<path>]
|
|
572
|
+
Git merge driver for catalogs (%O %A %B %P): merges entry by entry and leaves conflict
|
|
573
|
+
markers only where both sides changed one translation differently.`,
|
|
574
|
+
lsp: `vi18n lsp [--stdio]
|
|
575
|
+
Language server for editors: hovers with every locale's translation, diagnostics for missing
|
|
576
|
+
and invalid translations, go to the catalog entry. Speaks LSP on stdin/stdout.`,
|
|
577
|
+
mcp: `vi18n mcp
|
|
578
|
+
Model Context Protocol server for agents: status, check, extract and compile checks, translate
|
|
579
|
+
--dry-run, and reading and writing one translation. Speaks MCP on stdin/stdout.`
|
|
580
|
+
};
|
|
581
|
+
function helpText(command, version) {
|
|
582
|
+
if (command !== null) return `${COMMAND_HELP[command]}\n\n${GLOBAL_HELP}\n`;
|
|
583
|
+
return `vi18n ${version}\n\nUsage:\n${COMMANDS.map((name) => " " + COMMAND_HELP[name].split("\n")[0]).join("\n")}\n\n${GLOBAL_HELP}\n`;
|
|
584
|
+
}
|
|
585
|
+
// src/cli/run.ts
|
|
586
|
+
/**
|
|
587
|
+
* The `vi18n` binary minus the process (INTERNALS §2.14, §3.5): parse argv,
|
|
588
|
+
* run one command, map failures to exit codes, print the `--json` envelope.
|
|
589
|
+
* Tests call `run` in-process with recording `CliIo`s; `bin.ts` wires the
|
|
590
|
+
* real process to it.
|
|
591
|
+
*/
|
|
592
|
+
/**
|
|
593
|
+
* Each command loads only its own code: every CLI run is a fresh process,
|
|
594
|
+
* and loading every command made `extract` parse the AI, exchange and MF2
|
|
595
|
+
* modules it never calls.
|
|
596
|
+
*/
|
|
597
|
+
const RUNNERS = {
|
|
598
|
+
init: async () => (await import("./init-Cc7A-8VX.js")).init,
|
|
599
|
+
extract: async () => (await import("./extract-BxYchVmY.js")).extract,
|
|
600
|
+
check: async () => (await import("./check-CunekuYs.js")).check,
|
|
601
|
+
status: async () => (await import("./status-q6M3rBrh.js")).status,
|
|
602
|
+
compile: async () => (await import("./compile-hva0qjhZ.js")).compile,
|
|
603
|
+
translate: async () => (await import("./translate-BP4iVhOR.js")).translate,
|
|
604
|
+
migrate: async () => (await import("./migrate-1r43OBfe.js")).migrate,
|
|
605
|
+
sitemap: async () => (await import("./sitemap-CSAkm6oi.js")).sitemap,
|
|
606
|
+
export: async () => (await import("./export-D2tsqWIr.js")).exportCatalogs,
|
|
607
|
+
import: async () => (await import("./import-vSC29Cn4.js")).importCatalogs,
|
|
608
|
+
restore: async () => (await import("./restore-xlBIrtRt.js")).restore,
|
|
609
|
+
rename: async () => (await import("./rename-ZVGq9ZG1.js")).rename,
|
|
610
|
+
which: async () => (await import("./which-DFWk_KwN.js")).which,
|
|
611
|
+
"merge-driver": async () => (await import("./merge-driver-BLI8OtAc.js")).mergeDriver,
|
|
612
|
+
lsp: async () => (await import("./lsp-DvC11pBZ.js")).lsp,
|
|
613
|
+
mcp: async () => (await import("./mcp-D2zzOTBy.js")).mcp
|
|
614
|
+
};
|
|
615
|
+
async function runCommand(command, ctx, flags) {
|
|
616
|
+
return (await RUNNERS[command]())(ctx, flags);
|
|
617
|
+
}
|
|
618
|
+
async function run(argv, io) {
|
|
619
|
+
const parsed = parseCommandLine(argv, io.cwd);
|
|
620
|
+
if (parsed.kind === "run") return runParsed(parsed, io);
|
|
621
|
+
if (parsed.kind === "usage") return usage(parsed, io);
|
|
622
|
+
const text = parsed.kind === "version" ? VERSION + "\n" : helpText(parsed.command, VERSION);
|
|
623
|
+
if (parsed.json && parsed.command !== null) createOutput(io, "json").finish(parsed.command, EXIT.ok, parsed.kind === "version" ? { version: VERSION } : { help: text });
|
|
624
|
+
else io.stdout(text);
|
|
625
|
+
return EXIT.ok;
|
|
626
|
+
}
|
|
627
|
+
function usage(parsed, io) {
|
|
628
|
+
const out = createOutput(io, parsed.json ? "json" : "text");
|
|
629
|
+
out.addSecret(io.env[DEFAULT_CONFIG.ai.apiKeyEnv]);
|
|
630
|
+
const hint = parsed.command === null ? "vi18n --help" : `vi18n ${parsed.command} --help`;
|
|
631
|
+
io.stderr(out.redact(`vi18n: ${parsed.message}\nRun ${hint} for usage.\n`));
|
|
632
|
+
if (parsed.command !== null) out.finish(parsed.command, EXIT.usage, { usage: parsed.message });
|
|
633
|
+
return EXIT.usage;
|
|
634
|
+
}
|
|
635
|
+
function outputFormat(parsed) {
|
|
636
|
+
if (parsed.global.json) return "json";
|
|
637
|
+
return parsed.command === "check" ? parsed.flags.format : "text";
|
|
638
|
+
}
|
|
639
|
+
async function runParsed(parsed, io) {
|
|
640
|
+
const commandIo = {
|
|
641
|
+
...io,
|
|
642
|
+
cwd: parsed.global.cwd
|
|
643
|
+
};
|
|
644
|
+
const out = createOutput(commandIo, outputFormat(parsed));
|
|
645
|
+
out.addSecret(io.env[DEFAULT_CONFIG.ai.apiKeyEnv]);
|
|
646
|
+
const ctx = {
|
|
647
|
+
io: commandIo,
|
|
648
|
+
out,
|
|
649
|
+
global: parsed.global
|
|
650
|
+
};
|
|
651
|
+
let exitCode;
|
|
652
|
+
let data = null;
|
|
653
|
+
try {
|
|
654
|
+
const result = await runCommand(parsed.command, ctx, parsed.flags);
|
|
655
|
+
exitCode = result.exitCode;
|
|
656
|
+
data = result.data;
|
|
657
|
+
} catch (error) {
|
|
658
|
+
if (error instanceof CliExit) {
|
|
659
|
+
out.report(error.diagnostics);
|
|
660
|
+
exitCode = error.exitCode;
|
|
661
|
+
data = error.data;
|
|
662
|
+
} else if (isDiagnosticError(error)) {
|
|
663
|
+
out.report([error.diagnostic]);
|
|
664
|
+
exitCode = error.diagnostic.code.startsWith("config-") ? EXIT.usage : EXIT.failure;
|
|
665
|
+
} else {
|
|
666
|
+
const message = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
667
|
+
io.stderr(out.redact(`vi18n ${parsed.command}: ${message}\n`));
|
|
668
|
+
exitCode = EXIT.failure;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
out.finish(parsed.command, exitCode, data);
|
|
672
|
+
return exitCode;
|
|
673
|
+
}
|
|
674
|
+
export { run as t };
|
package/dist/scan-worker.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { _ as MessageOccurrence, g as MessageCodec, h as Diagnostic, i as ResolvedConfig } from "./types-
|
|
2
|
-
//#region src/core/extract/worker.d.ts
|
|
1
|
+
import { _ as MessageOccurrence, g as MessageCodec, h as Diagnostic, i as ResolvedConfig } from "./types-_4UdFhR9.js";
|
|
3
2
|
export interface FileTask {
|
|
4
3
|
/** Absolute path (a realpath from the file walk). */
|
|
5
4
|
file: string;
|
|
@@ -58,5 +57,4 @@ export type WorkerResponse = {
|
|
|
58
57
|
message: string;
|
|
59
58
|
stack?: string;
|
|
60
59
|
};
|
|
61
|
-
};
|
|
62
|
-
//#endregion
|
|
60
|
+
};
|
package/dist/scan-worker.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as ABORT_CODES, n as WORKER_MARKER, r as scanConfig, i as scanSource } from "./worker-
|
|
1
|
+
export { t as ABORT_CODES, n as WORKER_MARKER, r as scanConfig, i as scanSource } from "./worker-zlhNj4y3.js";
|