@verbaly/compiler 0.78.0 → 0.79.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 +3 -3
- package/dist/{claude-DZkzlC5g.js → claude-BtdaNZEw.js} +2 -2
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -3
- package/dist/{run-kySCrf3Z.js → run-DobJrwby.js} +1436 -1405
- package/package.json +2 -2
|
@@ -10,7 +10,7 @@ import { applyEdits, modify, parse as parse$2 } from "jsonc-parser";
|
|
|
10
10
|
import picomatch from "picomatch";
|
|
11
11
|
import MagicString from "magic-string";
|
|
12
12
|
import { parseArgs } from "node:util";
|
|
13
|
-
// src/host.ts
|
|
13
|
+
// src/config/host.ts
|
|
14
14
|
const HOSTS = [
|
|
15
15
|
{
|
|
16
16
|
name: "nuxt",
|
|
@@ -130,6 +130,11 @@ function installCommand(root, packages, dev = false) {
|
|
|
130
130
|
const manager = packageManager(root);
|
|
131
131
|
return `${manager} ${manager === "npm" ? "install" : "add"}${dev ? manager === "bun" ? " -d" : " -D" : ""} ${packages.join(" ")}`;
|
|
132
132
|
}
|
|
133
|
+
function cliReachable(root) {
|
|
134
|
+
const bin = join(root, "node_modules", ".bin");
|
|
135
|
+
return existsSync(join(bin, "verbaly")) || existsSync(join(bin, "verbaly.CMD"));
|
|
136
|
+
}
|
|
137
|
+
const CLI_INSTALL_FIX = "add `@verbaly/compiler` to your dev dependencies, then `npx verbaly` resolves";
|
|
133
138
|
const TYPE_SLOTS = {
|
|
134
139
|
next: [".verbaly", "types.d.ts"],
|
|
135
140
|
astro: [
|
|
@@ -145,12 +150,140 @@ function defaultTypesPath(root, host = detectHost(root)?.name) {
|
|
|
145
150
|
if (slot) return join(root, ...slot);
|
|
146
151
|
return existsSync(join(root, "src")) ? join(root, "src", "verbaly.d.ts") : join(root, "verbaly.d.ts");
|
|
147
152
|
}
|
|
148
|
-
// src/
|
|
153
|
+
// src/util/warn.ts
|
|
154
|
+
const warned = /* @__PURE__ */ new Set();
|
|
155
|
+
function warnOnce(message, dedupeKey = message) {
|
|
156
|
+
if (warned.has(dedupeKey)) return;
|
|
157
|
+
warned.add(dedupeKey);
|
|
158
|
+
console.warn(`[verbaly] ${message}`);
|
|
159
|
+
}
|
|
160
|
+
function warnParseError(file, message) {
|
|
161
|
+
warnOnce(`${file}: could not be parsed (${message}), its messages were not extracted`);
|
|
162
|
+
}
|
|
163
|
+
// src/config/config.ts
|
|
164
|
+
const SOURCE_EXTENSIONS = "{js,jsx,ts,tsx,mjs,mts,svelte,vue,astro}";
|
|
165
|
+
const PSEUDO_LOCALE = "en-XA";
|
|
166
|
+
function resolveConfig(config = {}) {
|
|
167
|
+
const root = resolve(config.root ?? process.cwd());
|
|
168
|
+
const dir = resolve(root, config.dir ?? "locales");
|
|
169
|
+
const sourceLocale = config.sourceLocale ?? "en";
|
|
170
|
+
const host = detectHost(root)?.name;
|
|
171
|
+
const localesDeclared = config.locales !== void 0;
|
|
172
|
+
const locales = /* @__PURE__ */ new Set([sourceLocale, ...config.locales ?? []]);
|
|
173
|
+
if (!localesDeclared && existsSync(dir)) {
|
|
174
|
+
for (const file of readdirSync(dir)) if (file.endsWith(".json") && !file.startsWith(".") && file !== `en-XA.json`) locales.add(file.slice(0, -5));
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
root,
|
|
178
|
+
dir,
|
|
179
|
+
sourceLocale,
|
|
180
|
+
localesDeclared,
|
|
181
|
+
routing: config.routing ?? (config.render ? "prefix-except-source" : "no-prefix"),
|
|
182
|
+
icu: config.icu,
|
|
183
|
+
relative: config.relative,
|
|
184
|
+
locales: [...locales],
|
|
185
|
+
include: config.include ?? [`{src,app}/**/*.{js,jsx,ts,tsx,mjs,mts,svelte,vue,astro}`],
|
|
186
|
+
exclude: config.exclude ?? ["**/node_modules/**", "**/dist/**"],
|
|
187
|
+
dts: typeof config.dts === "string" ? resolve(root, config.dts) : config.dts === false ? false : defaultTypesPath(root, host),
|
|
188
|
+
translate: config.translate ?? {},
|
|
189
|
+
render: config.render ?? {},
|
|
190
|
+
bundle: config.bundle ?? {},
|
|
191
|
+
host,
|
|
192
|
+
trailingSlash: config.trailingSlash
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const CONFIG_FILES = [
|
|
196
|
+
"verbaly.config.js",
|
|
197
|
+
"verbaly.config.mjs",
|
|
198
|
+
"verbaly.config.ts",
|
|
199
|
+
"verbaly.config.mts",
|
|
200
|
+
"verbaly.config.json"
|
|
201
|
+
];
|
|
202
|
+
function findConfigFile(root) {
|
|
203
|
+
return CONFIG_FILES.find((name) => existsSync(join(root, name)));
|
|
204
|
+
}
|
|
205
|
+
async function loadConfigFile(root) {
|
|
206
|
+
for (const name of ["verbaly.config.js", "verbaly.config.mjs"]) {
|
|
207
|
+
const path = join(root, name);
|
|
208
|
+
if (existsSync(path)) {
|
|
209
|
+
const url = `${pathToFileURL(path).href}?mtime=${statSync(path).mtimeMs}`;
|
|
210
|
+
delete createRequire(import.meta.url).cache[resolve(path)];
|
|
211
|
+
return (await import(url)).default ?? {};
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
for (const name of ["verbaly.config.ts", "verbaly.config.mts"]) {
|
|
215
|
+
const path = join(root, name);
|
|
216
|
+
if (existsSync(path)) return loadTsConfig(path);
|
|
217
|
+
}
|
|
218
|
+
const jsonPath = join(root, "verbaly.config.json");
|
|
219
|
+
if (existsSync(jsonPath)) return readJsonConfig(jsonPath);
|
|
220
|
+
return {};
|
|
221
|
+
}
|
|
222
|
+
function readJsonConfig(path) {
|
|
223
|
+
const content = readFileSync(path, "utf8");
|
|
224
|
+
const body = content.charCodeAt(0) === 65279 ? content.slice(1) : content;
|
|
225
|
+
try {
|
|
226
|
+
return JSON.parse(body);
|
|
227
|
+
} catch (error) {
|
|
228
|
+
throw new Error(`[verbaly] ${path} is not valid JSON: ${error.message}`, { cause: error });
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
async function loadTsConfig(path) {
|
|
232
|
+
const { createJiti } = await import("jiti");
|
|
233
|
+
const mod = await createJiti(import.meta.url, {
|
|
234
|
+
fsCache: false,
|
|
235
|
+
moduleCache: false,
|
|
236
|
+
interopDefault: false
|
|
237
|
+
}).import(path);
|
|
238
|
+
return mod.__esModule ? mod.default ?? {} : mod;
|
|
239
|
+
}
|
|
240
|
+
function isModuleNotFound(error, name) {
|
|
241
|
+
return error instanceof Error && error.code === "ERR_MODULE_NOT_FOUND" && error.message.includes(name);
|
|
242
|
+
}
|
|
243
|
+
function targetLocales(cfg, override) {
|
|
244
|
+
return (override ?? cfg.locales).filter((locale) => locale !== cfg.sourceLocale && cfg.locales.includes(locale));
|
|
245
|
+
}
|
|
246
|
+
async function loadConfig(root, overrides = {}, from = {}) {
|
|
247
|
+
const fileConfig = await loadConfigFile(root);
|
|
248
|
+
if (from.plugin) warnPluginOnly(root, fileConfig, overrides);
|
|
249
|
+
return resolveConfig({
|
|
250
|
+
...fileConfig,
|
|
251
|
+
...definedOnly(overrides),
|
|
252
|
+
root
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
const READ_BY_CLI = [
|
|
256
|
+
"sourceLocale",
|
|
257
|
+
"locales",
|
|
258
|
+
"dir",
|
|
259
|
+
"include",
|
|
260
|
+
"exclude"
|
|
261
|
+
];
|
|
262
|
+
function warnPluginOnly(root, file, overrides) {
|
|
263
|
+
const cli = resolveConfig({
|
|
264
|
+
...file,
|
|
265
|
+
root
|
|
266
|
+
});
|
|
267
|
+
const build = resolveConfig({
|
|
268
|
+
...file,
|
|
269
|
+
...definedOnly(overrides),
|
|
270
|
+
root
|
|
271
|
+
});
|
|
272
|
+
const keys = READ_BY_CLI.filter((key) => overrides[key] !== void 0 && JSON.stringify(cli[key]) !== JSON.stringify(build[key]));
|
|
273
|
+
if (keys.length === 0) return;
|
|
274
|
+
const names = keys.length > 1 ? `${keys.slice(0, -1).join(", ")} and ${keys.at(-1)}` : keys[0];
|
|
275
|
+
const [verb, pronoun] = keys.length > 1 ? ["are", "them"] : ["is", "it"];
|
|
276
|
+
warnOnce(`${names} ${verb} set in the plugin options, which \`verbaly check\` and \`verbaly extract\` never read: move ${pronoun} to verbaly.config so the command line checks what the build ships`, `plugin-only:${root}`);
|
|
277
|
+
}
|
|
278
|
+
function definedOnly(config) {
|
|
279
|
+
return Object.fromEntries(Object.entries(config).filter(([, value]) => value !== void 0));
|
|
280
|
+
}
|
|
281
|
+
// src/util/eol.ts
|
|
149
282
|
function withLineEndings(text, existing) {
|
|
150
283
|
const first = existing?.indexOf("\n") ?? -1;
|
|
151
284
|
return first > 0 && existing[first - 1] === "\r" ? text.replace(/\r?\n/g, "\r\n") : text;
|
|
152
285
|
}
|
|
153
|
-
// src/catalog.ts
|
|
286
|
+
// src/catalog/catalog.ts
|
|
154
287
|
function emptyCatalog() {
|
|
155
288
|
return Object.create(null);
|
|
156
289
|
}
|
|
@@ -305,264 +438,19 @@ function someLeaf(tree, pattern) {
|
|
|
305
438
|
} else if (isTree(value) && someLeaf(value, pattern)) return true;
|
|
306
439
|
return false;
|
|
307
440
|
}
|
|
308
|
-
// src/
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
a: "á",
|
|
312
|
-
b: "ƀ",
|
|
313
|
-
c: "ç",
|
|
314
|
-
d: "đ",
|
|
315
|
-
e: "é",
|
|
316
|
-
f: "ƒ",
|
|
317
|
-
g: "ğ",
|
|
318
|
-
h: "ĥ",
|
|
319
|
-
i: "í",
|
|
320
|
-
j: "ĵ",
|
|
321
|
-
k: "ķ",
|
|
322
|
-
l: "ĺ",
|
|
323
|
-
m: "ɱ",
|
|
324
|
-
n: "ñ",
|
|
325
|
-
o: "ó",
|
|
326
|
-
p: "þ",
|
|
327
|
-
q: "ǫ",
|
|
328
|
-
r: "ŕ",
|
|
329
|
-
s: "š",
|
|
330
|
-
t: "ţ",
|
|
331
|
-
u: "ú",
|
|
332
|
-
v: "ṽ",
|
|
333
|
-
w: "ŵ",
|
|
334
|
-
x: "ẋ",
|
|
335
|
-
y: "ý",
|
|
336
|
-
z: "ž",
|
|
337
|
-
A: "Á",
|
|
338
|
-
B: "Ɓ",
|
|
339
|
-
C: "Ç",
|
|
340
|
-
D: "Đ",
|
|
341
|
-
E: "É",
|
|
342
|
-
F: "Ƒ",
|
|
343
|
-
G: "Ğ",
|
|
344
|
-
H: "Ĥ",
|
|
345
|
-
I: "Í",
|
|
346
|
-
J: "Ĵ",
|
|
347
|
-
K: "Ķ",
|
|
348
|
-
L: "Ĺ",
|
|
349
|
-
M: "Ḿ",
|
|
350
|
-
N: "Ñ",
|
|
351
|
-
O: "Ó",
|
|
352
|
-
P: "Þ",
|
|
353
|
-
Q: "Ǫ",
|
|
354
|
-
R: "Ŕ",
|
|
355
|
-
S: "Š",
|
|
356
|
-
T: "Ţ",
|
|
357
|
-
U: "Ú",
|
|
358
|
-
V: "Ṽ",
|
|
359
|
-
W: "Ŵ",
|
|
360
|
-
X: "Ẍ",
|
|
361
|
-
Y: "Ý",
|
|
362
|
-
Z: "Ž"
|
|
363
|
-
};
|
|
364
|
-
const TAG_AT = /<\/?[a-zA-Z][\w-]*\/?>/y;
|
|
365
|
-
function pseudoLocalize(message) {
|
|
366
|
-
let out = "";
|
|
367
|
-
let letters = 0;
|
|
368
|
-
let i = 0;
|
|
369
|
-
while (i < message.length) {
|
|
370
|
-
const two = message.slice(i, i + 2);
|
|
371
|
-
if (two === "{{" || two === "}}" || two === "||" || two === "##") {
|
|
372
|
-
out += two;
|
|
373
|
-
i += 2;
|
|
374
|
-
continue;
|
|
375
|
-
}
|
|
376
|
-
const ch = message[i];
|
|
377
|
-
if (ch === "{") {
|
|
378
|
-
const end = matchBrace$1(message, i);
|
|
379
|
-
out += message.slice(i, end);
|
|
380
|
-
i = end;
|
|
381
|
-
continue;
|
|
382
|
-
}
|
|
383
|
-
if (ch === "<") {
|
|
384
|
-
TAG_AT.lastIndex = i;
|
|
385
|
-
const m = TAG_AT.exec(message);
|
|
386
|
-
if (m) {
|
|
387
|
-
out += m[0];
|
|
388
|
-
i += m[0].length;
|
|
389
|
-
continue;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
const mapped = ACCENTS[ch];
|
|
393
|
-
if (mapped) {
|
|
394
|
-
out += mapped;
|
|
395
|
-
letters += 1;
|
|
396
|
-
} else out += ch;
|
|
397
|
-
i += 1;
|
|
398
|
-
}
|
|
399
|
-
const pad = "~".repeat(Math.ceil(letters / 3));
|
|
400
|
-
return `⟦${out}${pad ? " " + pad : ""}⟧`;
|
|
441
|
+
// src/util/text.ts
|
|
442
|
+
function counted(count, noun, many = `${noun}s`) {
|
|
443
|
+
return `${count} ${count === 1 ? noun : many}`;
|
|
401
444
|
}
|
|
402
|
-
function
|
|
403
|
-
|
|
404
|
-
for (let i = start; i < message.length; i++) {
|
|
405
|
-
const two = message.slice(i, i + 2);
|
|
406
|
-
if (two === "{{" || two === "}}") {
|
|
407
|
-
i += 1;
|
|
408
|
-
continue;
|
|
409
|
-
}
|
|
410
|
-
const ch = message[i];
|
|
411
|
-
if (ch === "{") depth += 1;
|
|
412
|
-
else if (ch === "}") {
|
|
413
|
-
depth -= 1;
|
|
414
|
-
if (depth === 0) return i + 1;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
return message.length;
|
|
445
|
+
function truncate(text, max) {
|
|
446
|
+
return text.length > max ? text.slice(0, max - 1) + "…" : text;
|
|
418
447
|
}
|
|
419
|
-
function
|
|
420
|
-
|
|
421
|
-
const target = emptyCatalog();
|
|
422
|
-
for (const [key, msg] of Object.entries(source)) target[key] = msg ? pseudoLocalize(msg) : "";
|
|
423
|
-
catalogs[locale] = target;
|
|
424
|
-
return Object.keys(target).filter((key) => target[key]);
|
|
448
|
+
function byCodeUnit(a, b) {
|
|
449
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
425
450
|
}
|
|
426
|
-
// src/
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
if (warned.has(dedupeKey)) return;
|
|
430
|
-
warned.add(dedupeKey);
|
|
431
|
-
console.warn(`[verbaly] ${message}`);
|
|
432
|
-
}
|
|
433
|
-
function warnParseError(file, message) {
|
|
434
|
-
warnOnce(`${file}: could not be parsed (${message}), its messages were not extracted`);
|
|
435
|
-
}
|
|
436
|
-
// src/config.ts
|
|
437
|
-
const SOURCE_EXTENSIONS = "{js,jsx,ts,tsx,mjs,mts,svelte,vue,astro}";
|
|
438
|
-
function resolveConfig(config = {}) {
|
|
439
|
-
const root = resolve(config.root ?? process.cwd());
|
|
440
|
-
const dir = resolve(root, config.dir ?? "locales");
|
|
441
|
-
const sourceLocale = config.sourceLocale ?? "en";
|
|
442
|
-
const host = detectHost(root)?.name;
|
|
443
|
-
const localesDeclared = config.locales !== void 0;
|
|
444
|
-
const locales = /* @__PURE__ */ new Set([sourceLocale, ...config.locales ?? []]);
|
|
445
|
-
if (!localesDeclared && existsSync(dir)) {
|
|
446
|
-
for (const file of readdirSync(dir)) if (file.endsWith(".json") && !file.startsWith(".") && file !== `en-XA.json`) locales.add(file.slice(0, -5));
|
|
447
|
-
}
|
|
448
|
-
return {
|
|
449
|
-
root,
|
|
450
|
-
dir,
|
|
451
|
-
sourceLocale,
|
|
452
|
-
localesDeclared,
|
|
453
|
-
routing: config.routing ?? (config.render ? "prefix-except-source" : "no-prefix"),
|
|
454
|
-
icu: config.icu,
|
|
455
|
-
relative: config.relative,
|
|
456
|
-
locales: [...locales],
|
|
457
|
-
include: config.include ?? [`{src,app}/**/*.{js,jsx,ts,tsx,mjs,mts,svelte,vue,astro}`],
|
|
458
|
-
exclude: config.exclude ?? ["**/node_modules/**", "**/dist/**"],
|
|
459
|
-
dts: typeof config.dts === "string" ? resolve(root, config.dts) : config.dts === false ? false : defaultTypesPath(root, host),
|
|
460
|
-
translate: config.translate ?? {},
|
|
461
|
-
render: config.render ?? {},
|
|
462
|
-
bundle: config.bundle ?? {},
|
|
463
|
-
host,
|
|
464
|
-
trailingSlash: config.trailingSlash
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
const CONFIG_FILES = [
|
|
468
|
-
"verbaly.config.js",
|
|
469
|
-
"verbaly.config.mjs",
|
|
470
|
-
"verbaly.config.ts",
|
|
471
|
-
"verbaly.config.mts",
|
|
472
|
-
"verbaly.config.json"
|
|
473
|
-
];
|
|
474
|
-
function findConfigFile(root) {
|
|
475
|
-
return CONFIG_FILES.find((name) => existsSync(join(root, name)));
|
|
476
|
-
}
|
|
477
|
-
async function loadConfigFile(root) {
|
|
478
|
-
for (const name of ["verbaly.config.js", "verbaly.config.mjs"]) {
|
|
479
|
-
const path = join(root, name);
|
|
480
|
-
if (existsSync(path)) {
|
|
481
|
-
const url = `${pathToFileURL(path).href}?mtime=${statSync(path).mtimeMs}`;
|
|
482
|
-
delete createRequire(import.meta.url).cache[resolve(path)];
|
|
483
|
-
return (await import(url)).default ?? {};
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
for (const name of ["verbaly.config.ts", "verbaly.config.mts"]) {
|
|
487
|
-
const path = join(root, name);
|
|
488
|
-
if (existsSync(path)) return loadTsConfig(path);
|
|
489
|
-
}
|
|
490
|
-
const jsonPath = join(root, "verbaly.config.json");
|
|
491
|
-
if (existsSync(jsonPath)) return readJsonConfig(jsonPath);
|
|
492
|
-
return {};
|
|
493
|
-
}
|
|
494
|
-
function readJsonConfig(path) {
|
|
495
|
-
const content = readFileSync(path, "utf8");
|
|
496
|
-
const body = content.charCodeAt(0) === 65279 ? content.slice(1) : content;
|
|
497
|
-
try {
|
|
498
|
-
return JSON.parse(body);
|
|
499
|
-
} catch (error) {
|
|
500
|
-
throw new Error(`[verbaly] ${path} is not valid JSON: ${error.message}`, { cause: error });
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
async function loadTsConfig(path) {
|
|
504
|
-
const { createJiti } = await import("jiti");
|
|
505
|
-
const mod = await createJiti(import.meta.url, {
|
|
506
|
-
fsCache: false,
|
|
507
|
-
moduleCache: false,
|
|
508
|
-
interopDefault: false
|
|
509
|
-
}).import(path);
|
|
510
|
-
return mod.__esModule ? mod.default ?? {} : mod;
|
|
511
|
-
}
|
|
512
|
-
function isModuleNotFound(error, name) {
|
|
513
|
-
return error instanceof Error && error.code === "ERR_MODULE_NOT_FOUND" && error.message.includes(name);
|
|
514
|
-
}
|
|
515
|
-
function targetLocales(cfg, override) {
|
|
516
|
-
return (override ?? cfg.locales).filter((locale) => locale !== cfg.sourceLocale && cfg.locales.includes(locale));
|
|
517
|
-
}
|
|
518
|
-
async function loadConfig(root, overrides = {}, from = {}) {
|
|
519
|
-
const fileConfig = await loadConfigFile(root);
|
|
520
|
-
if (from.plugin) warnPluginOnly(root, fileConfig, overrides);
|
|
521
|
-
return resolveConfig({
|
|
522
|
-
...fileConfig,
|
|
523
|
-
...definedOnly(overrides),
|
|
524
|
-
root
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
const READ_BY_CLI = [
|
|
528
|
-
"sourceLocale",
|
|
529
|
-
"locales",
|
|
530
|
-
"dir",
|
|
531
|
-
"include",
|
|
532
|
-
"exclude"
|
|
533
|
-
];
|
|
534
|
-
function warnPluginOnly(root, file, overrides) {
|
|
535
|
-
const cli = resolveConfig({
|
|
536
|
-
...file,
|
|
537
|
-
root
|
|
538
|
-
});
|
|
539
|
-
const build = resolveConfig({
|
|
540
|
-
...file,
|
|
541
|
-
...definedOnly(overrides),
|
|
542
|
-
root
|
|
543
|
-
});
|
|
544
|
-
const keys = READ_BY_CLI.filter((key) => overrides[key] !== void 0 && JSON.stringify(cli[key]) !== JSON.stringify(build[key]));
|
|
545
|
-
if (keys.length === 0) return;
|
|
546
|
-
const names = keys.length > 1 ? `${keys.slice(0, -1).join(", ")} and ${keys.at(-1)}` : keys[0];
|
|
547
|
-
const [verb, pronoun] = keys.length > 1 ? ["are", "them"] : ["is", "it"];
|
|
548
|
-
warnOnce(`${names} ${verb} set in the plugin options, which \`verbaly check\` and \`verbaly extract\` never read: move ${pronoun} to verbaly.config so the command line checks what the build ships`, `plugin-only:${root}`);
|
|
549
|
-
}
|
|
550
|
-
function definedOnly(config) {
|
|
551
|
-
return Object.fromEntries(Object.entries(config).filter(([, value]) => value !== void 0));
|
|
552
|
-
}
|
|
553
|
-
// src/text.ts
|
|
554
|
-
function counted(count, noun, many = `${noun}s`) {
|
|
555
|
-
return `${count} ${count === 1 ? noun : many}`;
|
|
556
|
-
}
|
|
557
|
-
function truncate(text, max) {
|
|
558
|
-
return text.length > max ? text.slice(0, max - 1) + "…" : text;
|
|
559
|
-
}
|
|
560
|
-
function byCodeUnit(a, b) {
|
|
561
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
562
|
-
}
|
|
563
|
-
// src/bundle.ts
|
|
564
|
-
function isExcluded(key, prefixes) {
|
|
565
|
-
return prefixes.some((prefix) => key === prefix || key.startsWith(`${prefix}.`));
|
|
451
|
+
// src/emit/bundle.ts
|
|
452
|
+
function isExcluded(key, prefixes) {
|
|
453
|
+
return prefixes.some((prefix) => key === prefix || key.startsWith(`${prefix}.`));
|
|
566
454
|
}
|
|
567
455
|
function clientCatalogs(cfg, catalogs) {
|
|
568
456
|
const prefixes = cfg.bundle.exclude ?? [];
|
|
@@ -603,7 +491,7 @@ function auditBundle(cfg, catalogs, registry) {
|
|
|
603
491
|
function formatBundleIssue(issue) {
|
|
604
492
|
return `bundle.exclude "${issue.prefix}" ${issue.problem}`;
|
|
605
493
|
}
|
|
606
|
-
// src/registry.ts
|
|
494
|
+
// src/scan/registry.ts
|
|
607
495
|
var MessageRegistry = class {
|
|
608
496
|
files = /* @__PURE__ */ new Map();
|
|
609
497
|
update(file, analysis) {
|
|
@@ -676,18 +564,18 @@ var MessageRegistry = class {
|
|
|
676
564
|
function earlier(a, b) {
|
|
677
565
|
return a.file === b.file ? a.start < b.start : a.file < b.file;
|
|
678
566
|
}
|
|
679
|
-
// src/ids.ts
|
|
567
|
+
// src/util/ids.ts
|
|
680
568
|
const VIRTUAL_ID = "virtual:verbaly";
|
|
681
569
|
const APP_ID = "verbaly/app";
|
|
682
570
|
const LOCALE_IMPORT = "@verbaly/app/locale/";
|
|
683
571
|
function isAppModule(source) {
|
|
684
572
|
return source === "verbaly/app" || source === "virtual:verbaly";
|
|
685
573
|
}
|
|
686
|
-
// src/key.ts
|
|
574
|
+
// src/util/key.ts
|
|
687
575
|
function stableKey(message) {
|
|
688
576
|
return createHash("sha256").update(message).digest("base64url").slice(0, 8);
|
|
689
577
|
}
|
|
690
|
-
// src/analyze.ts
|
|
578
|
+
// src/scan/analyze.ts
|
|
691
579
|
function parseErrorMessage(error) {
|
|
692
580
|
return error instanceof Error ? error.message : String(error);
|
|
693
581
|
}
|
|
@@ -1213,7 +1101,7 @@ function walk$1(node, visit) {
|
|
|
1213
1101
|
function isNode(value) {
|
|
1214
1102
|
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
1215
1103
|
}
|
|
1216
|
-
// src/sfc.ts
|
|
1104
|
+
// src/scan/sfc.ts
|
|
1217
1105
|
const SFC_FILE_RE = /\.(?:svelte|vue|astro)$/;
|
|
1218
1106
|
function analyzeFile(code, file) {
|
|
1219
1107
|
if (SFC_FILE_RE.test(file)) return analyzeSfc(code, file);
|
|
@@ -1403,7 +1291,7 @@ function stringEnd(code, start) {
|
|
|
1403
1291
|
else i += 1;
|
|
1404
1292
|
return code.length;
|
|
1405
1293
|
}
|
|
1406
|
-
// src/extract.ts
|
|
1294
|
+
// src/scan/extract.ts
|
|
1407
1295
|
const kept = /* @__PURE__ */ new WeakMap();
|
|
1408
1296
|
async function extractProject(cfg, options = {}) {
|
|
1409
1297
|
const files = await glob(cfg.include, {
|
|
@@ -1488,7 +1376,7 @@ function pruneCatalogs(cfg, catalogs, registry) {
|
|
|
1488
1376
|
}
|
|
1489
1377
|
return removed;
|
|
1490
1378
|
}
|
|
1491
|
-
// src/validate.ts
|
|
1379
|
+
// src/gate/validate.ts
|
|
1492
1380
|
let remembered = /* @__PURE__ */ new Map();
|
|
1493
1381
|
let reading;
|
|
1494
1382
|
function read(message) {
|
|
@@ -1699,7 +1587,7 @@ function reachableCategories(locale, ordinal) {
|
|
|
1699
1587
|
reachable.set(cacheKey, out);
|
|
1700
1588
|
return out;
|
|
1701
1589
|
}
|
|
1702
|
-
// src/params.ts
|
|
1590
|
+
// src/emit/params.ts
|
|
1703
1591
|
const NUMBER_FORMATS = /* @__PURE__ */ new Set([
|
|
1704
1592
|
"number",
|
|
1705
1593
|
"integer",
|
|
@@ -1741,7 +1629,7 @@ function renderParamType(types) {
|
|
|
1741
1629
|
]) members.add(m);
|
|
1742
1630
|
return [...members].join(" | ");
|
|
1743
1631
|
}
|
|
1744
|
-
// src/tsconfig.ts
|
|
1632
|
+
// src/config/tsconfig.ts
|
|
1745
1633
|
function readTsconfig(root) {
|
|
1746
1634
|
const path = join(root, "tsconfig.json");
|
|
1747
1635
|
let text;
|
|
@@ -1800,7 +1688,7 @@ function includeTypes(root, file) {
|
|
|
1800
1688
|
writeFileSync(read.path, applyEdits(read.text, edits));
|
|
1801
1689
|
return "added";
|
|
1802
1690
|
}
|
|
1803
|
-
// src/codegen.ts
|
|
1691
|
+
// src/emit/codegen.ts
|
|
1804
1692
|
const DTS_HEADER = "// generated by verbaly: do not edit";
|
|
1805
1693
|
const SLICE_HELPERS = `function readSlice(root, path) {
|
|
1806
1694
|
const locale = readPath({ supported: locales, path });
|
|
@@ -2079,7 +1967,7 @@ function removeRootDts(cfg, target) {
|
|
|
2079
1967
|
rmSync(old);
|
|
2080
1968
|
warnOnce(`the types live in ${relative(cfg.root, target).replaceAll("\\", "/")} now, so the verbaly.d.ts Verbaly wrote at the root was removed`);
|
|
2081
1969
|
}
|
|
2082
|
-
// src/findings.ts
|
|
1970
|
+
// src/gate/findings.ts
|
|
2083
1971
|
function siteOf(msg) {
|
|
2084
1972
|
return {
|
|
2085
1973
|
file: msg.file,
|
|
@@ -2200,7 +2088,7 @@ function createDevReporter(root, print = (line) => console.warn(`[verbaly] ${lin
|
|
|
2200
2088
|
if (fresh.length > cap) print(`and ${fresh.length - cap} more: \`npx verbaly doctor\` names them`);
|
|
2201
2089
|
} };
|
|
2202
2090
|
}
|
|
2203
|
-
// src/state.ts
|
|
2091
|
+
// src/catalog/state.ts
|
|
2204
2092
|
const STATE_FILE = "verbaly.lock";
|
|
2205
2093
|
const LOCK_VERSION = 1;
|
|
2206
2094
|
const README = "Written by Verbaly: the source text each translation was made for, which ones are drafts, and which languages migrate converted. Commit it with your catalogs and never edit it: deleting it marks every draft as reviewed.";
|
|
@@ -2533,7 +2421,7 @@ function readFingerprints(value) {
|
|
|
2533
2421
|
}
|
|
2534
2422
|
return out;
|
|
2535
2423
|
}
|
|
2536
|
-
// src/project.ts
|
|
2424
|
+
// src/project/project.ts
|
|
2537
2425
|
async function syncProject(cfg, options = {}) {
|
|
2538
2426
|
const registry = options.registry ?? await extractProject(cfg);
|
|
2539
2427
|
const catalogs = options.catalogs ?? loadCatalogs(cfg);
|
|
@@ -2589,619 +2477,269 @@ function confirmFromDisk(cfg, catalogs, registry) {
|
|
|
2589
2477
|
registry.update(file, analyzeFile(code, file));
|
|
2590
2478
|
}
|
|
2591
2479
|
}
|
|
2592
|
-
// src/
|
|
2593
|
-
|
|
2594
|
-
"
|
|
2595
|
-
"react-i18next",
|
|
2596
|
-
"vue-i18n",
|
|
2597
|
-
"react-intl",
|
|
2598
|
-
"next-intl",
|
|
2599
|
-
"svelte-i18n"
|
|
2600
|
-
];
|
|
2601
|
-
function detectLibraries(root) {
|
|
2602
|
-
const path = join(root, "package.json");
|
|
2603
|
-
if (!existsSync(path)) return [];
|
|
2604
|
-
let manifest;
|
|
2605
|
-
try {
|
|
2606
|
-
manifest = JSON.parse(readFileSync(path, "utf8"));
|
|
2607
|
-
} catch {
|
|
2608
|
-
return [];
|
|
2609
|
-
}
|
|
2610
|
-
const deps = {
|
|
2611
|
-
...manifest.dependencies,
|
|
2612
|
-
...manifest.devDependencies
|
|
2613
|
-
};
|
|
2614
|
-
return KNOWN.filter((name) => deps[name] !== void 0);
|
|
2615
|
-
}
|
|
2616
|
-
const PLAIN = /\{\{\s*([A-Za-z_$][\w$]*)\s*\}\}/g;
|
|
2617
|
-
const FORMATTED = /\{\{\s*-?\s*[A-Za-z_$][\w$]*\s*,[^}]*\}\}/;
|
|
2618
|
-
const UNESCAPED = /\{\{\s*-\s*[A-Za-z_$][\w$]*\s*\}\}/;
|
|
2619
|
-
const NESTED = /\$t\(/;
|
|
2620
|
-
const DOUBLE = /\{\{[^{}]*\}\}/;
|
|
2621
|
-
const DOUBLES = new RegExp(DOUBLE.source, "g");
|
|
2622
|
-
const ONE_PLAIN = new RegExp(`^${PLAIN.source}$`);
|
|
2623
|
-
const NAME = /^\s*([A-Za-z_$][\w$]*)\s*$/;
|
|
2624
|
-
const CATEGORIES = [
|
|
2625
|
-
"zero",
|
|
2626
|
-
"one",
|
|
2627
|
-
"two",
|
|
2628
|
-
"few",
|
|
2629
|
-
"many",
|
|
2630
|
-
"other"
|
|
2631
|
-
];
|
|
2632
|
-
const SUFFIX = new RegExp(`^(.*)_(${[...CATEGORIES, "plural"].join("|")})$`);
|
|
2633
|
-
function i18nextProblem(text) {
|
|
2634
|
-
if (NESTED.test(text)) return "uses $t() nesting, which has no direct equivalent";
|
|
2635
|
-
if (UNESCAPED.test(text)) return "uses {{- name}}, so decide whether the message is rich";
|
|
2636
|
-
if (FORMATTED.test(text)) return "uses an i18next format, which needs the matching Verbaly one";
|
|
2637
|
-
for (const [double] of text.matchAll(DOUBLES)) if (!ONE_PLAIN.test(double)) return "uses {{…}} with more than a name, which needs a Verbaly param";
|
|
2638
|
-
}
|
|
2639
|
-
function convertBraces(text) {
|
|
2640
|
-
let out = "";
|
|
2641
|
-
let last = 0;
|
|
2642
|
-
for (const match of text.matchAll(PLAIN)) {
|
|
2643
|
-
out += escapeBraces(text.slice(last, match.index)) + `{${match[1]}}`;
|
|
2644
|
-
last = match.index + match[0].length;
|
|
2645
|
-
}
|
|
2646
|
-
return out + escapeBraces(text.slice(last));
|
|
2647
|
-
}
|
|
2648
|
-
function escapeBraces(text) {
|
|
2649
|
-
return text.replace(/[{}]/g, (brace) => brace + brace);
|
|
2480
|
+
// src/gate/check.ts
|
|
2481
|
+
function gatePasses(result) {
|
|
2482
|
+
return result.missing.length === 0 && result.unknown.length === 0 && result.collisions.length === 0 && !result.broken.some((entry) => entry.severity === "error");
|
|
2650
2483
|
}
|
|
2651
|
-
function
|
|
2652
|
-
|
|
2653
|
-
let i = 0;
|
|
2654
|
-
while (i < text.length) {
|
|
2655
|
-
const ch = text[i];
|
|
2656
|
-
if ((ch === "{" || ch === "}") && text[i + 1] === ch) {
|
|
2657
|
-
out += ch + ch;
|
|
2658
|
-
i += 2;
|
|
2659
|
-
} else if (ch === "{") {
|
|
2660
|
-
const close = text.indexOf("}", i);
|
|
2661
|
-
const name = close < 0 ? void 0 : NAME.exec(text.slice(i + 1, close))?.[1];
|
|
2662
|
-
if (name === void 0) return void 0;
|
|
2663
|
-
out += name === "count" ? "#" : `{${name}}`;
|
|
2664
|
-
i = close + 1;
|
|
2665
|
-
} else {
|
|
2666
|
-
out += ch === "#" || ch === "|" || ch === "}" ? ch + ch : ch;
|
|
2667
|
-
i += 1;
|
|
2668
|
-
}
|
|
2669
|
-
}
|
|
2670
|
-
return out;
|
|
2484
|
+
function warningCount(result) {
|
|
2485
|
+
return result.broken.filter((entry) => entry.severity === "warning").length + result.extra.length + result.divergent.length + result.outdated.length;
|
|
2671
2486
|
}
|
|
2672
|
-
function
|
|
2673
|
-
return
|
|
2487
|
+
function check(cfg, catalogs, registry, fingerprints = {}) {
|
|
2488
|
+
return gatePass(() => checkPass(cfg, catalogs, registry, fingerprints));
|
|
2674
2489
|
}
|
|
2675
|
-
function
|
|
2676
|
-
const
|
|
2677
|
-
const
|
|
2678
|
-
for (const
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2490
|
+
function checkPass(cfg, catalogs, registry, fingerprints) {
|
|
2491
|
+
const extracted = registry.messages();
|
|
2492
|
+
const flat = {};
|
|
2493
|
+
for (const locale of cfg.locales) flat[locale] = flatView(catalogs[locale] ?? {});
|
|
2494
|
+
const source = flat[cfg.sourceLocale] ?? {};
|
|
2495
|
+
const shipped = shippedCatalogs(cfg, flat, registry);
|
|
2496
|
+
const sourceText = shipped[cfg.sourceLocale];
|
|
2497
|
+
const used = registry.usedKeys();
|
|
2498
|
+
const unknown = [];
|
|
2499
|
+
for (const [key, files] of registry.usedKeys(true)) if (!(extracted.has(key) || cfg.locales.some((locale) => flat[locale]?.[key] !== void 0))) unknown.push({
|
|
2500
|
+
key,
|
|
2501
|
+
files
|
|
2502
|
+
});
|
|
2503
|
+
const needed = /* @__PURE__ */ new Set([...extracted.keys(), ...Object.keys(source)]);
|
|
2504
|
+
const missing = [];
|
|
2505
|
+
for (const key of extracted.keys()) if (!source[key]) missing.push({
|
|
2506
|
+
locale: cfg.sourceLocale,
|
|
2507
|
+
key,
|
|
2508
|
+
source: extracted.get(key)?.message
|
|
2509
|
+
});
|
|
2510
|
+
for (const locale of cfg.locales) {
|
|
2511
|
+
if (locale === cfg.sourceLocale) continue;
|
|
2512
|
+
for (const key of needed) if (!flat[locale]?.[key]) missing.push({
|
|
2513
|
+
locale,
|
|
2686
2514
|
key,
|
|
2687
|
-
|
|
2515
|
+
source: source[key] ?? extracted.get(key)?.message
|
|
2688
2516
|
});
|
|
2689
2517
|
}
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
key: base,
|
|
2694
|
-
value: bare
|
|
2695
|
-
});
|
|
2696
|
-
else if (bare !== void 0) {
|
|
2697
|
-
skipped.push({
|
|
2698
|
-
locale,
|
|
2699
|
-
key: base,
|
|
2700
|
-
reason: `"${base}" already exists, so merging would overwrite it`
|
|
2701
|
-
});
|
|
2702
|
-
continue;
|
|
2703
|
-
}
|
|
2704
|
-
if (!forms.has("other")) {
|
|
2705
|
-
skipped.push({
|
|
2706
|
-
locale,
|
|
2707
|
-
key: base,
|
|
2708
|
-
reason: "no _other form, so the block would have no catch-all"
|
|
2709
|
-
});
|
|
2710
|
-
continue;
|
|
2711
|
-
}
|
|
2712
|
-
if (forms.size === 1) {
|
|
2713
|
-
skipped.push({
|
|
2714
|
-
locale,
|
|
2715
|
-
key: base,
|
|
2716
|
-
reason: "only a plural form, so add the singular before merging"
|
|
2717
|
-
});
|
|
2718
|
-
continue;
|
|
2719
|
-
}
|
|
2720
|
-
const sorted = [...forms.entries()].sort((a, b) => order(a[0], b[0]));
|
|
2721
|
-
const cases = [];
|
|
2722
|
-
let problem;
|
|
2723
|
-
for (const [category, form] of sorted) {
|
|
2724
|
-
problem = fromI18next ? i18nextProblem(form.value) : void 0;
|
|
2725
|
-
const body = problem ? void 0 : toVariant(fromI18next ? convertBraces(form.value) : form.value);
|
|
2726
|
-
if (body === void 0) {
|
|
2727
|
-
problem ??= "a form holds more than a name in braces, so merge it by hand";
|
|
2728
|
-
break;
|
|
2729
|
-
}
|
|
2730
|
-
cases.push(`${category}: ${body}`);
|
|
2731
|
-
}
|
|
2732
|
-
if (problem) {
|
|
2733
|
-
skipped.push({
|
|
2734
|
-
locale,
|
|
2735
|
-
key: base,
|
|
2736
|
-
reason: problem
|
|
2737
|
-
});
|
|
2738
|
-
continue;
|
|
2739
|
-
}
|
|
2740
|
-
const merged = `{count | ${cases.join(" | ")}}`;
|
|
2741
|
-
for (const [, form] of sorted) delete out[form.key];
|
|
2742
|
-
out[base] = merged;
|
|
2743
|
-
plurals.push({
|
|
2518
|
+
const broken = [];
|
|
2519
|
+
const add = (locale, key, issues) => {
|
|
2520
|
+
for (const issue of issues) broken.push({
|
|
2744
2521
|
locale,
|
|
2745
|
-
key
|
|
2746
|
-
|
|
2747
|
-
|
|
2522
|
+
key,
|
|
2523
|
+
severity: issue.severity,
|
|
2524
|
+
issue: issue.message
|
|
2525
|
+
});
|
|
2526
|
+
};
|
|
2527
|
+
const divergent = [];
|
|
2528
|
+
for (const [key, entry] of extracted) {
|
|
2529
|
+
const written = source[key];
|
|
2530
|
+
if (written && written !== entry.message) divergent.push({
|
|
2531
|
+
key,
|
|
2532
|
+
catalog: written,
|
|
2533
|
+
code: siteOf(entry)
|
|
2748
2534
|
});
|
|
2749
2535
|
}
|
|
2750
|
-
|
|
2751
|
-
function migrateCatalogs(cfg, options = {}) {
|
|
2752
|
-
const braces = [];
|
|
2753
|
-
const plurals = [];
|
|
2754
|
-
const skipped = [];
|
|
2755
|
-
const written = [];
|
|
2756
|
-
const state = loadState(cfg);
|
|
2757
|
-
const done = new Set(state.migrated ?? []);
|
|
2758
|
-
const catalogs = new Map(cfg.locales.map((locale) => [locale, readCatalog(cfg, locale)]));
|
|
2759
|
-
const pending = cfg.locales.filter((locale) => !done.has(locale));
|
|
2760
|
-
const fromI18next = pending.some((locale) => Object.values(catalogs.get(locale)).some((value) => typeof value === "string" && (DOUBLE.test(value) || NESTED.test(value))));
|
|
2536
|
+
for (const [key, text] of Object.entries(sourceText)) add(cfg.sourceLocale, key, validateMessage(text, cfg.sourceLocale));
|
|
2761
2537
|
for (const locale of cfg.locales) {
|
|
2762
|
-
|
|
2763
|
-
const
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
if (problem) {
|
|
2769
|
-
skipped.push({
|
|
2770
|
-
locale,
|
|
2771
|
-
key,
|
|
2772
|
-
reason: problem
|
|
2773
|
-
});
|
|
2774
|
-
continue;
|
|
2775
|
-
}
|
|
2776
|
-
const after = convertBraces(value);
|
|
2777
|
-
if (after !== value) {
|
|
2778
|
-
braces.push({
|
|
2779
|
-
locale,
|
|
2780
|
-
key,
|
|
2781
|
-
before: value,
|
|
2782
|
-
after
|
|
2783
|
-
});
|
|
2784
|
-
out[key] = after;
|
|
2785
|
-
}
|
|
2786
|
-
}
|
|
2787
|
-
if (options.plurals) mergePlurals(locale, catalog, out, plurals, skipped, convert);
|
|
2788
|
-
if ((braces.some((b) => b.locale === locale) || plurals.some((p) => p.locale === locale)) && options.write) {
|
|
2789
|
-
writeCatalog(cfg, locale, out);
|
|
2790
|
-
written.push(locale);
|
|
2538
|
+
if (locale === cfg.sourceLocale) continue;
|
|
2539
|
+
for (const [key, translated] of Object.entries(flat[locale] ?? {})) {
|
|
2540
|
+
if (!translated) continue;
|
|
2541
|
+
add(locale, key, validateMessage(translated, locale));
|
|
2542
|
+
const text = sourceText[key];
|
|
2543
|
+
if (text) add(locale, key, validatePair(text, translated));
|
|
2791
2544
|
}
|
|
2792
2545
|
}
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
if (
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2546
|
+
const extra = [];
|
|
2547
|
+
for (const locale of cfg.locales) {
|
|
2548
|
+
if (locale === cfg.sourceLocale) continue;
|
|
2549
|
+
for (const key of Object.keys(flat[locale] ?? {})) {
|
|
2550
|
+
if (source[key] !== void 0 || extracted.has(key)) continue;
|
|
2551
|
+
extra.push({
|
|
2552
|
+
locale,
|
|
2553
|
+
key,
|
|
2554
|
+
files: used.get(key) ?? []
|
|
2555
|
+
});
|
|
2556
|
+
}
|
|
2799
2557
|
}
|
|
2800
|
-
const
|
|
2558
|
+
const collisions = collisionEntries(registry);
|
|
2801
2559
|
return {
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2560
|
+
ok: gatePasses({
|
|
2561
|
+
missing,
|
|
2562
|
+
unknown,
|
|
2563
|
+
broken,
|
|
2564
|
+
collisions
|
|
2565
|
+
}),
|
|
2566
|
+
missing,
|
|
2567
|
+
unknown,
|
|
2568
|
+
broken,
|
|
2569
|
+
extra,
|
|
2570
|
+
collisions,
|
|
2571
|
+
divergent,
|
|
2572
|
+
outdated: outdatedTranslations(cfg, shipped, fingerprints)
|
|
2808
2573
|
};
|
|
2809
2574
|
}
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2575
|
+
function formatCheckResult(result, root) {
|
|
2576
|
+
const show = (file) => root ? relative(root, file).replaceAll("\\", "/") : file;
|
|
2577
|
+
const lines = [];
|
|
2578
|
+
if (result.missing.length > 0) {
|
|
2579
|
+
lines.push("missing translations:");
|
|
2580
|
+
for (const entry of result.missing) {
|
|
2581
|
+
const hint = entry.source ? `: "${truncate(entry.source, 40)}"` : "";
|
|
2582
|
+
lines.push(` [${entry.locale}] ${entry.key}${hint}`);
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
if (result.unknown.length > 0) {
|
|
2586
|
+
lines.push("unknown keys (not in any catalog):");
|
|
2587
|
+
for (const entry of result.unknown) lines.push(` ${entry.key} (used in ${entry.files.map(show).join(", ")})`);
|
|
2588
|
+
}
|
|
2589
|
+
const errors = result.broken.filter((entry) => entry.severity === "error");
|
|
2590
|
+
if (errors.length > 0) {
|
|
2591
|
+
lines.push("broken translations:");
|
|
2592
|
+
for (const entry of errors) lines.push(` [${entry.locale}] ${entry.key}: ${entry.issue}`);
|
|
2593
|
+
}
|
|
2594
|
+
if (result.collisions.length > 0) {
|
|
2595
|
+
lines.push("keys written with more than one text:");
|
|
2596
|
+
for (const entry of result.collisions) lines.push(` ${formatCollision(entry, root)}`);
|
|
2817
2597
|
}
|
|
2598
|
+
return lines.join("\n");
|
|
2818
2599
|
}
|
|
2819
|
-
function
|
|
2820
|
-
const
|
|
2821
|
-
|
|
2600
|
+
function formatBuildReport(result, sourceLocale, root, cap = 5) {
|
|
2601
|
+
const show = (file) => root ? relative(root, file).replaceAll("\\", "/") : file;
|
|
2602
|
+
const lines = [];
|
|
2603
|
+
const list = (entries, line) => {
|
|
2604
|
+
for (const entry of entries.slice(0, cap)) lines.push(` ${line(entry)}`);
|
|
2605
|
+
if (entries.length > cap) lines.push(` and ${entries.length - cap} more`);
|
|
2606
|
+
};
|
|
2607
|
+
const broken = result.broken.filter((entry) => entry.severity === "error");
|
|
2608
|
+
if (broken.length > 0) {
|
|
2609
|
+
lines.push(`✗ the build goes on with ${counted(broken.length, "broken translation")}, each rendering differently from its source:`);
|
|
2610
|
+
list(broken, (entry) => `[${entry.locale}] ${entry.key}: ${entry.issue}`);
|
|
2611
|
+
}
|
|
2612
|
+
if (result.collisions.length > 0) {
|
|
2613
|
+
lines.push(`✗ the build goes on with ${counted(result.collisions.length, "key")} written with more than one text:`);
|
|
2614
|
+
list(result.collisions, (entry) => formatCollision(entry, root));
|
|
2615
|
+
}
|
|
2616
|
+
const quoted = (entry) => entry.source ? `: "${truncate(entry.source, 40)}"` : "";
|
|
2617
|
+
const untranslated = result.missing.filter((entry) => entry.locale !== sourceLocale);
|
|
2618
|
+
if (untranslated.length > 0) {
|
|
2619
|
+
lines.push(`⚠ the build goes on without ${counted(untranslated.length, "translation")}, shown in ${sourceLocale} instead:`);
|
|
2620
|
+
list(untranslated, (entry) => `[${entry.locale}] ${entry.key}${quoted(entry)}`);
|
|
2621
|
+
}
|
|
2622
|
+
if (result.unknown.length > 0) {
|
|
2623
|
+
lines.push(`⚠ the build goes on with ${counted(result.unknown.length, "key")} no catalog has, so the key itself shows:`);
|
|
2624
|
+
list(result.unknown, (entry) => `${entry.key} (used in ${entry.files.map(show).join(", ")})`);
|
|
2625
|
+
}
|
|
2626
|
+
const unsynced = result.missing.filter((entry) => entry.locale === sourceLocale);
|
|
2627
|
+
if (unsynced.length > 0) lines.push(`⚠ the build goes on with ${counted(unsynced.length, "text")} the ${sourceLocale} catalog does not have yet, taken from the code`);
|
|
2628
|
+
return lines;
|
|
2822
2629
|
}
|
|
2823
|
-
function
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2630
|
+
function checkNextSteps(result, cliReachable = true) {
|
|
2631
|
+
const steps = [];
|
|
2632
|
+
if (result.missing.length > 0) steps.push("missing: run `npx verbaly extract` to scaffold the keys, then fill them (or run `npx verbaly translate`)");
|
|
2633
|
+
if (result.unknown.length > 0) steps.push("unknown keys: the key used in the code is in no catalog, fix the key or run `npx verbaly extract`");
|
|
2634
|
+
if (result.broken.some((entry) => entry.severity === "error")) steps.push("broken: a translation has to keep the params, tags and plural cases of its source message");
|
|
2635
|
+
if (result.collisions.length > 0) steps.push("collisions: give each text its own key in t.id(…), or write the same text in every place");
|
|
2636
|
+
if (steps.length > 0 && !cliReachable) steps.push(`the verbaly command is not linked in this project: ${CLI_INSTALL_FIX}`);
|
|
2637
|
+
return steps.join("\n");
|
|
2827
2638
|
}
|
|
2828
|
-
|
|
2829
|
-
const
|
|
2830
|
-
|
|
2831
|
-
"
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
"
|
|
2837
|
-
"translations",
|
|
2838
|
-
"src/translations",
|
|
2839
|
-
"messages"
|
|
2840
|
-
];
|
|
2841
|
-
function existingCatalogs(root) {
|
|
2842
|
-
return CATALOG_DIRS.find((dir) => {
|
|
2843
|
-
try {
|
|
2844
|
-
return readdirSync(join(root, dir)).some((file) => file.endsWith(".json") && isLocaleTag(file.slice(0, -5)));
|
|
2845
|
-
} catch {
|
|
2846
|
-
return false;
|
|
2847
|
-
}
|
|
2848
|
-
});
|
|
2639
|
+
function formatCheckWarnings(result, root, options = {}) {
|
|
2640
|
+
const lines = result.broken.filter((entry) => entry.severity === "warning").map((entry) => ` [${entry.locale}] ${entry.key}: ${entry.issue}`);
|
|
2641
|
+
for (const entry of result.extra) lines.push(entry.files.length > 0 ? ` [${entry.locale}] ${entry.key}: only this translation has it, so the source language shows the key itself` : ` [${entry.locale}] ${entry.key}: only this translation has it, and no code reads it`);
|
|
2642
|
+
for (const { key, catalog, code } of result.divergent) lines.push(` ${key}: the source catalog says "${truncate(catalog, 40)}" and the code says "${truncate(code.message, 40)}" (${sourcePlace(code, root)}): the code wins, so edit the text there (extract writes it into the catalog)`);
|
|
2643
|
+
if (!options.outdatedFails) for (const entry of result.outdated) lines.push(` ${formatFinding({
|
|
2644
|
+
kind: "outdated",
|
|
2645
|
+
...entry
|
|
2646
|
+
}, root)}`);
|
|
2647
|
+
return lines.join("\n");
|
|
2849
2648
|
}
|
|
2850
|
-
function
|
|
2851
|
-
const
|
|
2852
|
-
|
|
2853
|
-
}
|
|
2854
|
-
const
|
|
2855
|
-
|
|
2856
|
-
const
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
}
|
|
2863
|
-
async function init(input = {}) {
|
|
2864
|
-
const root = input.root ?? process.cwd();
|
|
2865
|
-
const created = [];
|
|
2866
|
-
const skipped = [];
|
|
2867
|
-
const renamed = [];
|
|
2868
|
-
const refused = [];
|
|
2869
|
-
const typed = input.locales?.flatMap((locale) => {
|
|
2870
|
-
if (isLocaleTag(locale)) return [locale];
|
|
2871
|
-
const near = suggestTag(locale);
|
|
2872
|
-
if (near) renamed.push({
|
|
2873
|
-
from: locale,
|
|
2874
|
-
to: near
|
|
2875
|
-
});
|
|
2876
|
-
else refused.push(locale);
|
|
2877
|
-
return near ? [near] : [];
|
|
2878
|
-
});
|
|
2879
|
-
const locales = typed && [...new Set(typed)];
|
|
2880
|
-
let sourceLocale = input.sourceLocale;
|
|
2881
|
-
if (sourceLocale !== void 0 && !isLocaleTag(sourceLocale)) {
|
|
2882
|
-
const near = suggestTag(sourceLocale);
|
|
2883
|
-
if (!near) throw new Error(`[verbaly] "${sourceLocale}" is not a locale tag: pass --source with one like en or pt-BR`);
|
|
2884
|
-
renamed.push({
|
|
2885
|
-
from: sourceLocale,
|
|
2886
|
-
to: near
|
|
2649
|
+
function githubCheckAnnotations(result, registry, cfg, options = {}) {
|
|
2650
|
+
const messages = registry.messages();
|
|
2651
|
+
const rel = (file) => escapeProperty(relative(cfg.root, file).replaceAll("\\", "/"));
|
|
2652
|
+
const at = (file, line) => `file=${rel(file)}${line ? `,line=${line}` : ""}`;
|
|
2653
|
+
const lines = [];
|
|
2654
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
2655
|
+
for (const entry of result.missing) {
|
|
2656
|
+
const grouped = byKey.get(entry.key);
|
|
2657
|
+
if (grouped) grouped.locales.push(entry.locale);
|
|
2658
|
+
else byKey.set(entry.key, {
|
|
2659
|
+
...entry,
|
|
2660
|
+
locales: [entry.locale]
|
|
2887
2661
|
});
|
|
2888
|
-
sourceLocale = near;
|
|
2889
2662
|
}
|
|
2890
|
-
const
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
const typescript = existsSync(join(root, "tsconfig.json"));
|
|
2897
|
-
const configFile = existing ?? (typescript ? "verbaly.config.ts" : "verbaly.config.mjs");
|
|
2898
|
-
const found = existing || options.dir ? void 0 : existingCatalogs(root);
|
|
2899
|
-
if (existing) skipped.push(existing);
|
|
2900
|
-
else {
|
|
2901
|
-
const dir = found === "locales" ? void 0 : found;
|
|
2902
|
-
writeFileSync(join(root, configFile), configSource({
|
|
2903
|
-
...options,
|
|
2904
|
-
dir: options.dir ?? dir
|
|
2905
|
-
}, typescript));
|
|
2906
|
-
created.push(configFile);
|
|
2663
|
+
for (const entry of byKey.values()) {
|
|
2664
|
+
const origin = messages.get(entry.key);
|
|
2665
|
+
const hint = entry.source ? `: "${truncate(entry.source, 60)}"` : "";
|
|
2666
|
+
const text = escapeData(`missing [${entry.locales.join(", ")}] ${entry.key}${hint}`);
|
|
2667
|
+
if (origin) lines.push(`::error ${at(origin.file, origin.line)}::${text}`);
|
|
2668
|
+
else lines.push(`::error::${text}`);
|
|
2907
2669
|
}
|
|
2908
|
-
const
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
else {
|
|
2921
|
-
writeFileSync(file, "{}\n");
|
|
2922
|
-
created.push(label);
|
|
2670
|
+
for (const entry of result.unknown) {
|
|
2671
|
+
const text = escapeData(`unknown key "${entry.key}" (not in any catalog)`);
|
|
2672
|
+
const file = entry.files[0];
|
|
2673
|
+
lines.push(file ? `::error file=${rel(file)}::${text}` : `::error::${text}`);
|
|
2674
|
+
}
|
|
2675
|
+
for (const entry of result.broken) {
|
|
2676
|
+
const origin = messages.get(entry.key);
|
|
2677
|
+
const text = escapeData(`[${entry.locale}] ${entry.key}: ${entry.issue}`);
|
|
2678
|
+
const command = entry.severity === "error" ? "error" : "warning";
|
|
2679
|
+
if (!origin) {
|
|
2680
|
+
lines.push(`::${command}::${text}`);
|
|
2681
|
+
continue;
|
|
2923
2682
|
}
|
|
2683
|
+
lines.push(`::${command} ${at(origin.file, origin.line)}::${text}`);
|
|
2924
2684
|
}
|
|
2925
|
-
const
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
}
|
|
2685
|
+
for (const entry of result.extra) {
|
|
2686
|
+
const text = escapeData(`[${entry.locale}] ${entry.key}: only this translation has it`);
|
|
2687
|
+
const file = entry.files[0];
|
|
2688
|
+
lines.push(file ? `::warning file=${rel(file)}::${text}` : `::warning::${text}`);
|
|
2689
|
+
}
|
|
2690
|
+
for (const { key, sites } of result.collisions) {
|
|
2691
|
+
const texts = new Set(sites.map((place) => place.message)).size;
|
|
2692
|
+
const text = escapeData(`"${key}" has ${counted(texts, "text")}, and every place shows the first one`);
|
|
2693
|
+
for (const place of sites) lines.push(`::error ${at(place.file, place.line)}::${text}`);
|
|
2694
|
+
}
|
|
2695
|
+
for (const { key, code } of result.divergent) {
|
|
2696
|
+
const text = escapeData(`"${key}": the source catalog has another text, the code's one ships`);
|
|
2697
|
+
lines.push(`::warning ${at(code.file, code.line)}::${text}`);
|
|
2698
|
+
}
|
|
2699
|
+
const outdated = options.outdatedFails ? "error" : "warning";
|
|
2700
|
+
for (const { locale, key } of result.outdated) {
|
|
2701
|
+
const text = escapeData(`[${locale}] ${key}: translated from an older source text`);
|
|
2702
|
+
lines.push(`::${outdated} file=${rel(catalogPath(cfg, locale))}::${text}`);
|
|
2703
|
+
}
|
|
2704
|
+
return lines;
|
|
2941
2705
|
}
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
return result.missing.length === 0 && result.unknown.length === 0 && result.collisions.length === 0 && !result.broken.some((entry) => entry.severity === "error");
|
|
2706
|
+
function escapeData(text) {
|
|
2707
|
+
return text.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A");
|
|
2945
2708
|
}
|
|
2946
|
-
function
|
|
2947
|
-
return
|
|
2709
|
+
function escapeProperty(text) {
|
|
2710
|
+
return escapeData(text).replaceAll(":", "%3A").replaceAll(",", "%2C");
|
|
2948
2711
|
}
|
|
2949
|
-
|
|
2950
|
-
|
|
2712
|
+
// src/scan/transform.ts
|
|
2713
|
+
function quote(text, single) {
|
|
2714
|
+
if (!single) return JSON.stringify(text);
|
|
2715
|
+
return `'${text.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
|
|
2951
2716
|
}
|
|
2952
|
-
function
|
|
2953
|
-
const
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
const
|
|
2958
|
-
const
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
for (const key of extracted.keys()) if (!source[key]) missing.push({
|
|
2968
|
-
locale: cfg.sourceLocale,
|
|
2969
|
-
key,
|
|
2970
|
-
source: extracted.get(key)?.message
|
|
2971
|
-
});
|
|
2972
|
-
for (const locale of cfg.locales) {
|
|
2973
|
-
if (locale === cfg.sourceLocale) continue;
|
|
2974
|
-
for (const key of needed) if (!flat[locale]?.[key]) missing.push({
|
|
2975
|
-
locale,
|
|
2976
|
-
key,
|
|
2977
|
-
source: source[key] ?? extracted.get(key)?.message
|
|
2978
|
-
});
|
|
2979
|
-
}
|
|
2980
|
-
const broken = [];
|
|
2981
|
-
const add = (locale, key, issues) => {
|
|
2982
|
-
for (const issue of issues) broken.push({
|
|
2983
|
-
locale,
|
|
2984
|
-
key,
|
|
2985
|
-
severity: issue.severity,
|
|
2986
|
-
issue: issue.message
|
|
2987
|
-
});
|
|
2988
|
-
};
|
|
2989
|
-
const divergent = [];
|
|
2990
|
-
for (const [key, entry] of extracted) {
|
|
2991
|
-
const written = source[key];
|
|
2992
|
-
if (written && written !== entry.message) divergent.push({
|
|
2993
|
-
key,
|
|
2994
|
-
catalog: written,
|
|
2995
|
-
code: siteOf(entry)
|
|
2996
|
-
});
|
|
2997
|
-
}
|
|
2998
|
-
for (const [key, text] of Object.entries(sourceText)) add(cfg.sourceLocale, key, validateMessage(text, cfg.sourceLocale));
|
|
2999
|
-
for (const locale of cfg.locales) {
|
|
3000
|
-
if (locale === cfg.sourceLocale) continue;
|
|
3001
|
-
for (const [key, translated] of Object.entries(flat[locale] ?? {})) {
|
|
3002
|
-
if (!translated) continue;
|
|
3003
|
-
add(locale, key, validateMessage(translated, locale));
|
|
3004
|
-
const text = sourceText[key];
|
|
3005
|
-
if (text) add(locale, key, validatePair(text, translated));
|
|
3006
|
-
}
|
|
3007
|
-
}
|
|
3008
|
-
const extra = [];
|
|
3009
|
-
for (const locale of cfg.locales) {
|
|
3010
|
-
if (locale === cfg.sourceLocale) continue;
|
|
3011
|
-
for (const key of Object.keys(flat[locale] ?? {})) {
|
|
3012
|
-
if (source[key] !== void 0 || extracted.has(key)) continue;
|
|
3013
|
-
extra.push({
|
|
3014
|
-
locale,
|
|
3015
|
-
key,
|
|
3016
|
-
files: used.get(key) ?? []
|
|
3017
|
-
});
|
|
2717
|
+
function transformCode(code, file, analysis) {
|
|
2718
|
+
const own = analysis ?? analyzeFile(code, file);
|
|
2719
|
+
if (!analysis && own.parseError) warnParseError(file, own.parseError);
|
|
2720
|
+
const { tagged } = own;
|
|
2721
|
+
if (tagged.length === 0) return null;
|
|
2722
|
+
const s = new MagicString(code);
|
|
2723
|
+
for (const msg of tagged) {
|
|
2724
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2725
|
+
const entries = msg.params.filter((p) => !seen.has(p.name) && seen.add(p.name));
|
|
2726
|
+
const pairs = entries.map((p) => `${quote(p.name, msg.singleQuote)}: ${code.slice(p.start, p.end)}`).join(", ");
|
|
2727
|
+
if (msg.jsx) {
|
|
2728
|
+
const values = entries.length ? ` values={{ ${pairs} }}` : "";
|
|
2729
|
+
const components = msg.jsx.components.length ? ` components={{ ${msg.jsx.components.map((c) => `${JSON.stringify(c.name)}: ${c.source}`).join(", ")} }}` : "";
|
|
2730
|
+
s.overwrite(msg.start, msg.end, `<${msg.jsx.name} id=${JSON.stringify(msg.key)}${values}${components} />`);
|
|
2731
|
+
continue;
|
|
3018
2732
|
}
|
|
2733
|
+
const tagSource = code.slice(msg.tagStart, msg.tagEnd);
|
|
2734
|
+
const args = entries.length ? `, { ${pairs} }` : "";
|
|
2735
|
+
s.overwrite(msg.start, msg.end, `${tagSource}(${quote(msg.key, msg.singleQuote)}${args})`);
|
|
3019
2736
|
}
|
|
3020
|
-
const collisions = collisionEntries(registry);
|
|
3021
2737
|
return {
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
unknown,
|
|
3025
|
-
broken,
|
|
3026
|
-
collisions
|
|
3027
|
-
}),
|
|
3028
|
-
missing,
|
|
3029
|
-
unknown,
|
|
3030
|
-
broken,
|
|
3031
|
-
extra,
|
|
3032
|
-
collisions,
|
|
3033
|
-
divergent,
|
|
3034
|
-
outdated: outdatedTranslations(cfg, shipped, fingerprints)
|
|
2738
|
+
code: s.toString(),
|
|
2739
|
+
map: s.generateMap({ hires: true })
|
|
3035
2740
|
};
|
|
3036
2741
|
}
|
|
3037
|
-
|
|
3038
|
-
const show = (file) => root ? relative(root, file).replaceAll("\\", "/") : file;
|
|
3039
|
-
const lines = [];
|
|
3040
|
-
if (result.missing.length > 0) {
|
|
3041
|
-
lines.push("missing translations:");
|
|
3042
|
-
for (const entry of result.missing) {
|
|
3043
|
-
const hint = entry.source ? `: "${truncate(entry.source, 40)}"` : "";
|
|
3044
|
-
lines.push(` [${entry.locale}] ${entry.key}${hint}`);
|
|
3045
|
-
}
|
|
3046
|
-
}
|
|
3047
|
-
if (result.unknown.length > 0) {
|
|
3048
|
-
lines.push("unknown keys (not in any catalog):");
|
|
3049
|
-
for (const entry of result.unknown) lines.push(` ${entry.key} (used in ${entry.files.map(show).join(", ")})`);
|
|
3050
|
-
}
|
|
3051
|
-
const errors = result.broken.filter((entry) => entry.severity === "error");
|
|
3052
|
-
if (errors.length > 0) {
|
|
3053
|
-
lines.push("broken translations:");
|
|
3054
|
-
for (const entry of errors) lines.push(` [${entry.locale}] ${entry.key}: ${entry.issue}`);
|
|
3055
|
-
}
|
|
3056
|
-
if (result.collisions.length > 0) {
|
|
3057
|
-
lines.push("keys written with more than one text:");
|
|
3058
|
-
for (const entry of result.collisions) lines.push(` ${formatCollision(entry, root)}`);
|
|
3059
|
-
}
|
|
3060
|
-
return lines.join("\n");
|
|
3061
|
-
}
|
|
3062
|
-
function formatBuildReport(result, sourceLocale, root, cap = 5) {
|
|
3063
|
-
const show = (file) => root ? relative(root, file).replaceAll("\\", "/") : file;
|
|
3064
|
-
const lines = [];
|
|
3065
|
-
const list = (entries, line) => {
|
|
3066
|
-
for (const entry of entries.slice(0, cap)) lines.push(` ${line(entry)}`);
|
|
3067
|
-
if (entries.length > cap) lines.push(` and ${entries.length - cap} more`);
|
|
3068
|
-
};
|
|
3069
|
-
const broken = result.broken.filter((entry) => entry.severity === "error");
|
|
3070
|
-
if (broken.length > 0) {
|
|
3071
|
-
lines.push(`✗ the build goes on with ${counted(broken.length, "broken translation")}, each rendering differently from its source:`);
|
|
3072
|
-
list(broken, (entry) => `[${entry.locale}] ${entry.key}: ${entry.issue}`);
|
|
3073
|
-
}
|
|
3074
|
-
if (result.collisions.length > 0) {
|
|
3075
|
-
lines.push(`✗ the build goes on with ${counted(result.collisions.length, "key")} written with more than one text:`);
|
|
3076
|
-
list(result.collisions, (entry) => formatCollision(entry, root));
|
|
3077
|
-
}
|
|
3078
|
-
const quoted = (entry) => entry.source ? `: "${truncate(entry.source, 40)}"` : "";
|
|
3079
|
-
const untranslated = result.missing.filter((entry) => entry.locale !== sourceLocale);
|
|
3080
|
-
if (untranslated.length > 0) {
|
|
3081
|
-
lines.push(`⚠ the build goes on without ${counted(untranslated.length, "translation")}, shown in ${sourceLocale} instead:`);
|
|
3082
|
-
list(untranslated, (entry) => `[${entry.locale}] ${entry.key}${quoted(entry)}`);
|
|
3083
|
-
}
|
|
3084
|
-
if (result.unknown.length > 0) {
|
|
3085
|
-
lines.push(`⚠ the build goes on with ${counted(result.unknown.length, "key")} no catalog has, so the key itself shows:`);
|
|
3086
|
-
list(result.unknown, (entry) => `${entry.key} (used in ${entry.files.map(show).join(", ")})`);
|
|
3087
|
-
}
|
|
3088
|
-
const unsynced = result.missing.filter((entry) => entry.locale === sourceLocale);
|
|
3089
|
-
if (unsynced.length > 0) lines.push(`⚠ the build goes on with ${counted(unsynced.length, "text")} the ${sourceLocale} catalog does not have yet, taken from the code`);
|
|
3090
|
-
return lines;
|
|
3091
|
-
}
|
|
3092
|
-
function checkNextSteps(result, cliReachable = true) {
|
|
3093
|
-
const steps = [];
|
|
3094
|
-
if (result.missing.length > 0) steps.push("missing: run `npx verbaly extract` to scaffold the keys, then fill them (or run `npx verbaly translate`)");
|
|
3095
|
-
if (result.unknown.length > 0) steps.push("unknown keys: the key used in the code is in no catalog, fix the key or run `npx verbaly extract`");
|
|
3096
|
-
if (result.broken.some((entry) => entry.severity === "error")) steps.push("broken: a translation has to keep the params, tags and plural cases of its source message");
|
|
3097
|
-
if (result.collisions.length > 0) steps.push("collisions: give each text its own key in t.id(…), or write the same text in every place");
|
|
3098
|
-
if (steps.length > 0 && !cliReachable) steps.push(`the verbaly command is not linked in this project: ${CLI_INSTALL_FIX}`);
|
|
3099
|
-
return steps.join("\n");
|
|
3100
|
-
}
|
|
3101
|
-
function formatCheckWarnings(result, root, options = {}) {
|
|
3102
|
-
const lines = result.broken.filter((entry) => entry.severity === "warning").map((entry) => ` [${entry.locale}] ${entry.key}: ${entry.issue}`);
|
|
3103
|
-
for (const entry of result.extra) lines.push(entry.files.length > 0 ? ` [${entry.locale}] ${entry.key}: only this translation has it, so the source language shows the key itself` : ` [${entry.locale}] ${entry.key}: only this translation has it, and no code reads it`);
|
|
3104
|
-
for (const { key, catalog, code } of result.divergent) lines.push(` ${key}: the source catalog says "${truncate(catalog, 40)}" and the code says "${truncate(code.message, 40)}" (${sourcePlace(code, root)}): the code wins, so edit the text there (extract writes it into the catalog)`);
|
|
3105
|
-
if (!options.outdatedFails) for (const entry of result.outdated) lines.push(` ${formatFinding({
|
|
3106
|
-
kind: "outdated",
|
|
3107
|
-
...entry
|
|
3108
|
-
}, root)}`);
|
|
3109
|
-
return lines.join("\n");
|
|
3110
|
-
}
|
|
3111
|
-
function githubCheckAnnotations(result, registry, cfg, options = {}) {
|
|
3112
|
-
const messages = registry.messages();
|
|
3113
|
-
const rel = (file) => escapeProperty(relative(cfg.root, file).replaceAll("\\", "/"));
|
|
3114
|
-
const at = (file, line) => `file=${rel(file)}${line ? `,line=${line}` : ""}`;
|
|
3115
|
-
const lines = [];
|
|
3116
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
3117
|
-
for (const entry of result.missing) {
|
|
3118
|
-
const grouped = byKey.get(entry.key);
|
|
3119
|
-
if (grouped) grouped.locales.push(entry.locale);
|
|
3120
|
-
else byKey.set(entry.key, {
|
|
3121
|
-
...entry,
|
|
3122
|
-
locales: [entry.locale]
|
|
3123
|
-
});
|
|
3124
|
-
}
|
|
3125
|
-
for (const entry of byKey.values()) {
|
|
3126
|
-
const origin = messages.get(entry.key);
|
|
3127
|
-
const hint = entry.source ? `: "${truncate(entry.source, 60)}"` : "";
|
|
3128
|
-
const text = escapeData(`missing [${entry.locales.join(", ")}] ${entry.key}${hint}`);
|
|
3129
|
-
if (origin) lines.push(`::error ${at(origin.file, origin.line)}::${text}`);
|
|
3130
|
-
else lines.push(`::error::${text}`);
|
|
3131
|
-
}
|
|
3132
|
-
for (const entry of result.unknown) {
|
|
3133
|
-
const text = escapeData(`unknown key "${entry.key}" (not in any catalog)`);
|
|
3134
|
-
const file = entry.files[0];
|
|
3135
|
-
lines.push(file ? `::error file=${rel(file)}::${text}` : `::error::${text}`);
|
|
3136
|
-
}
|
|
3137
|
-
for (const entry of result.broken) {
|
|
3138
|
-
const origin = messages.get(entry.key);
|
|
3139
|
-
const text = escapeData(`[${entry.locale}] ${entry.key}: ${entry.issue}`);
|
|
3140
|
-
const command = entry.severity === "error" ? "error" : "warning";
|
|
3141
|
-
if (!origin) {
|
|
3142
|
-
lines.push(`::${command}::${text}`);
|
|
3143
|
-
continue;
|
|
3144
|
-
}
|
|
3145
|
-
lines.push(`::${command} ${at(origin.file, origin.line)}::${text}`);
|
|
3146
|
-
}
|
|
3147
|
-
for (const entry of result.extra) {
|
|
3148
|
-
const text = escapeData(`[${entry.locale}] ${entry.key}: only this translation has it`);
|
|
3149
|
-
const file = entry.files[0];
|
|
3150
|
-
lines.push(file ? `::warning file=${rel(file)}::${text}` : `::warning::${text}`);
|
|
3151
|
-
}
|
|
3152
|
-
for (const { key, sites } of result.collisions) {
|
|
3153
|
-
const texts = new Set(sites.map((place) => place.message)).size;
|
|
3154
|
-
const text = escapeData(`"${key}" has ${counted(texts, "text")}, and every place shows the first one`);
|
|
3155
|
-
for (const place of sites) lines.push(`::error ${at(place.file, place.line)}::${text}`);
|
|
3156
|
-
}
|
|
3157
|
-
for (const { key, code } of result.divergent) {
|
|
3158
|
-
const text = escapeData(`"${key}": the source catalog has another text, the code's one ships`);
|
|
3159
|
-
lines.push(`::warning ${at(code.file, code.line)}::${text}`);
|
|
3160
|
-
}
|
|
3161
|
-
const outdated = options.outdatedFails ? "error" : "warning";
|
|
3162
|
-
for (const { locale, key } of result.outdated) {
|
|
3163
|
-
const text = escapeData(`[${locale}] ${key}: translated from an older source text`);
|
|
3164
|
-
lines.push(`::${outdated} file=${rel(catalogPath(cfg, locale))}::${text}`);
|
|
3165
|
-
}
|
|
3166
|
-
return lines;
|
|
3167
|
-
}
|
|
3168
|
-
function escapeData(text) {
|
|
3169
|
-
return text.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A");
|
|
3170
|
-
}
|
|
3171
|
-
function escapeProperty(text) {
|
|
3172
|
-
return escapeData(text).replaceAll(":", "%3A").replaceAll(",", "%2C");
|
|
3173
|
-
}
|
|
3174
|
-
// src/transform.ts
|
|
3175
|
-
function quote(text, single) {
|
|
3176
|
-
if (!single) return JSON.stringify(text);
|
|
3177
|
-
return `'${text.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
|
|
3178
|
-
}
|
|
3179
|
-
function transformCode(code, file, analysis) {
|
|
3180
|
-
const own = analysis ?? analyzeFile(code, file);
|
|
3181
|
-
if (!analysis && own.parseError) warnParseError(file, own.parseError);
|
|
3182
|
-
const { tagged } = own;
|
|
3183
|
-
if (tagged.length === 0) return null;
|
|
3184
|
-
const s = new MagicString(code);
|
|
3185
|
-
for (const msg of tagged) {
|
|
3186
|
-
const seen = /* @__PURE__ */ new Set();
|
|
3187
|
-
const entries = msg.params.filter((p) => !seen.has(p.name) && seen.add(p.name));
|
|
3188
|
-
const pairs = entries.map((p) => `${quote(p.name, msg.singleQuote)}: ${code.slice(p.start, p.end)}`).join(", ");
|
|
3189
|
-
if (msg.jsx) {
|
|
3190
|
-
const values = entries.length ? ` values={{ ${pairs} }}` : "";
|
|
3191
|
-
const components = msg.jsx.components.length ? ` components={{ ${msg.jsx.components.map((c) => `${JSON.stringify(c.name)}: ${c.source}`).join(", ")} }}` : "";
|
|
3192
|
-
s.overwrite(msg.start, msg.end, `<${msg.jsx.name} id=${JSON.stringify(msg.key)}${values}${components} />`);
|
|
3193
|
-
continue;
|
|
3194
|
-
}
|
|
3195
|
-
const tagSource = code.slice(msg.tagStart, msg.tagEnd);
|
|
3196
|
-
const args = entries.length ? `, { ${pairs} }` : "";
|
|
3197
|
-
s.overwrite(msg.start, msg.end, `${tagSource}(${quote(msg.key, msg.singleQuote)}${args})`);
|
|
3198
|
-
}
|
|
3199
|
-
return {
|
|
3200
|
-
code: s.toString(),
|
|
3201
|
-
map: s.generateMap({ hires: true })
|
|
3202
|
-
};
|
|
3203
|
-
}
|
|
3204
|
-
// src/plugin.ts
|
|
2742
|
+
// src/emit/plugin.ts
|
|
3205
2743
|
const RESOLVED_VIRTUAL_ID = "\0" + VIRTUAL_ID;
|
|
3206
2744
|
const LOCALE_MODULE_PREFIX = `${RESOLVED_VIRTUAL_ID}/locale/`;
|
|
3207
2745
|
const SOURCE_FILE_RE = /\.(?:[cm]?[jt]sx?|svelte|vue|astro)$/;
|
|
@@ -3241,6 +2779,15 @@ function transformSource(code, id, registry, scan) {
|
|
|
3241
2779
|
result: transformCode(code, id, analysis) ?? null
|
|
3242
2780
|
};
|
|
3243
2781
|
}
|
|
2782
|
+
function writeBuildTypes(cfg, catalogs) {
|
|
2783
|
+
try {
|
|
2784
|
+
writeDts(cfg, catalogs[cfg.sourceLocale] ?? {});
|
|
2785
|
+
} catch (error) {
|
|
2786
|
+
const code = error?.code;
|
|
2787
|
+
if (typeof code !== "string") throw error;
|
|
2788
|
+
warnOnce(`could not write the types to ${cfg.dts === false ? "" : relative(cfg.root, cfg.dts).replaceAll("\\", "/")} (${code}): run \`npx verbaly typegen\` where the project can be written`, `types:${cfg.root}`);
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
3244
2791
|
function runBuildGate(cfg, registry, failOnMissing) {
|
|
3245
2792
|
const catalogs = loadCatalogs(cfg);
|
|
3246
2793
|
for (const issue of auditBundle(cfg, catalogs, registry)) warnOnce(`${formatBundleIssue(issue)}\n fix: ${issue.fix}`, `bundle:${issue.prefix}`);
|
|
@@ -3285,7 +2832,7 @@ function buildFingerprints(cfg) {
|
|
|
3285
2832
|
if (problem) warnOnce(`${problem}, so outdated translations are not reported`, "gate:state");
|
|
3286
2833
|
return state.fingerprints;
|
|
3287
2834
|
}
|
|
3288
|
-
// src/scope.ts
|
|
2835
|
+
// src/scan/scope.ts
|
|
3289
2836
|
const TAGGED_HINT = /(?<![\w$.])\$?t(?:\.id\s*\([^)]*\))?\s*`/;
|
|
3290
2837
|
const NOT_SOURCE = [
|
|
3291
2838
|
"**/node_modules/**",
|
|
@@ -3351,7 +2898,7 @@ async function filesOutsideInclude(cfg) {
|
|
|
3351
2898
|
}
|
|
3352
2899
|
return found;
|
|
3353
2900
|
}
|
|
3354
|
-
// src/status.ts
|
|
2901
|
+
// src/gate/status.ts
|
|
3355
2902
|
function status(cfg, catalogs, registry, drafts = {}, fingerprints = {}) {
|
|
3356
2903
|
const extracted = registry.messages();
|
|
3357
2904
|
const flat = {};
|
|
@@ -3408,7 +2955,129 @@ function formatStatusResult(result) {
|
|
|
3408
2955
|
}
|
|
3409
2956
|
return lines.join("\n");
|
|
3410
2957
|
}
|
|
3411
|
-
// src/
|
|
2958
|
+
// src/cli/args.ts
|
|
2959
|
+
const OPTIONS = {
|
|
2960
|
+
root: { type: "string" },
|
|
2961
|
+
dir: { type: "string" },
|
|
2962
|
+
source: { type: "string" },
|
|
2963
|
+
locales: { type: "string" },
|
|
2964
|
+
prune: { type: "boolean" },
|
|
2965
|
+
watch: { type: "boolean" },
|
|
2966
|
+
write: { type: "boolean" },
|
|
2967
|
+
json: { type: "boolean" },
|
|
2968
|
+
drafts: { type: "boolean" },
|
|
2969
|
+
outdated: { type: "boolean" },
|
|
2970
|
+
draft: { type: "boolean" },
|
|
2971
|
+
approve: { type: "boolean" },
|
|
2972
|
+
reporter: { type: "string" },
|
|
2973
|
+
model: { type: "string" },
|
|
2974
|
+
locale: { type: "string" },
|
|
2975
|
+
site: { type: "string" },
|
|
2976
|
+
attribute: { type: "string" },
|
|
2977
|
+
base: { type: "string" },
|
|
2978
|
+
"base-url": { type: "string" },
|
|
2979
|
+
redirect: { type: "boolean" },
|
|
2980
|
+
sitemap: { type: "boolean" },
|
|
2981
|
+
clean: { type: "boolean" },
|
|
2982
|
+
"dry-run": { type: "boolean" },
|
|
2983
|
+
plurals: { type: "boolean" },
|
|
2984
|
+
format: { type: "string" },
|
|
2985
|
+
out: { type: "string" },
|
|
2986
|
+
missing: { type: "boolean" },
|
|
2987
|
+
overwrite: { type: "boolean" },
|
|
2988
|
+
help: {
|
|
2989
|
+
type: "boolean",
|
|
2990
|
+
short: "h"
|
|
2991
|
+
}
|
|
2992
|
+
};
|
|
2993
|
+
function parseCli(args) {
|
|
2994
|
+
return parseArgs({
|
|
2995
|
+
args,
|
|
2996
|
+
allowPositionals: true,
|
|
2997
|
+
options: OPTIONS
|
|
2998
|
+
});
|
|
2999
|
+
}
|
|
3000
|
+
function csv(value) {
|
|
3001
|
+
return value?.split(",").map((item) => item.trim()).filter(Boolean);
|
|
3002
|
+
}
|
|
3003
|
+
// src/cli/output.ts
|
|
3004
|
+
function sayLockNews(cfg, before) {
|
|
3005
|
+
const news = lockNews(cfg, before);
|
|
3006
|
+
if (news) console.log(` ${formatFinding({
|
|
3007
|
+
kind: "lock",
|
|
3008
|
+
...news
|
|
3009
|
+
}, cfg.root)}`);
|
|
3010
|
+
}
|
|
3011
|
+
function byLocale(entries) {
|
|
3012
|
+
const out = /* @__PURE__ */ new Map();
|
|
3013
|
+
for (const { locale, key } of entries) {
|
|
3014
|
+
const keys = out.get(locale);
|
|
3015
|
+
if (keys) keys.push(key);
|
|
3016
|
+
else out.set(locale, [key]);
|
|
3017
|
+
}
|
|
3018
|
+
return [...out];
|
|
3019
|
+
}
|
|
3020
|
+
// src/cli/commands/check.ts
|
|
3021
|
+
async function checkCommand(cfg, values) {
|
|
3022
|
+
const reporter = values.reporter ?? "text";
|
|
3023
|
+
if (reporter !== "text" && reporter !== "github") {
|
|
3024
|
+
console.error(`[verbaly] unknown reporter "${values.reporter}", use text or github`);
|
|
3025
|
+
process.exitCode = 1;
|
|
3026
|
+
return;
|
|
3027
|
+
}
|
|
3028
|
+
const registry = await extractProject(cfg);
|
|
3029
|
+
const catalogs = loadCatalogs(cfg);
|
|
3030
|
+
const state = checkState(cfg, values.drafts === true || values.outdated === true);
|
|
3031
|
+
const result = check(cfg, catalogs, registry, state.fingerprints);
|
|
3032
|
+
const unreviewed = values.drafts ? effectiveDrafts(state.drafts, catalogs) : {};
|
|
3033
|
+
const outdated = values.outdated ? result.outdated : [];
|
|
3034
|
+
const gated = { outdatedFails: values.outdated === true };
|
|
3035
|
+
if (reporter === "github") for (const line of githubCheckAnnotations(result, registry, cfg, gated)) console.error(line);
|
|
3036
|
+
else {
|
|
3037
|
+
const warnings = formatCheckWarnings(result, cfg.root, gated);
|
|
3038
|
+
if (warnings) console.warn(`[verbaly] warnings (the gate still passes)\n${warnings}`);
|
|
3039
|
+
}
|
|
3040
|
+
const awaiting = [...Object.entries(unreviewed).map(([locale, keys]) => ` [${locale}] ${keys.length} unreviewed: ${keys.join(", ")}`), ...byLocale(outdated).map(([locale, keys]) => ` [${locale}] ${keys.length} outdated: ${keys.join(", ")}`)];
|
|
3041
|
+
if (result.ok && awaiting.length === 0) {
|
|
3042
|
+
console.log("[verbaly] all translations complete ✓");
|
|
3043
|
+
return;
|
|
3044
|
+
}
|
|
3045
|
+
if (!result.ok) {
|
|
3046
|
+
const brokenCount = result.broken.filter((entry) => entry.severity === "error").length;
|
|
3047
|
+
const report = reporter === "github" ? `[verbaly] check failed: ${result.missing.length} missing, ${result.unknown.length} unknown, ${brokenCount} broken, ${counted(result.collisions.length, "collision")}` : `[verbaly] check failed\n${formatCheckResult(result, cfg.root)}`;
|
|
3048
|
+
console.error(`${report}\n${checkNextSteps(result)}`);
|
|
3049
|
+
}
|
|
3050
|
+
if (awaiting.length > 0) {
|
|
3051
|
+
for (const line of awaiting) console.error(line);
|
|
3052
|
+
console.error("[verbaly] check failed: translations awaiting review (run verbaly review, then --approve what holds)");
|
|
3053
|
+
}
|
|
3054
|
+
process.exitCode = 1;
|
|
3055
|
+
}
|
|
3056
|
+
function checkState(cfg, gating) {
|
|
3057
|
+
if (gating) return loadState(cfg);
|
|
3058
|
+
const { state, problem } = readState(cfg);
|
|
3059
|
+
if (problem) console.warn(`[verbaly] ${problem}, so outdated translations are not reported`);
|
|
3060
|
+
return state;
|
|
3061
|
+
}
|
|
3062
|
+
// src/util/tag.ts
|
|
3063
|
+
function isLocaleTag(tag) {
|
|
3064
|
+
try {
|
|
3065
|
+
Intl.getCanonicalLocales(tag);
|
|
3066
|
+
return true;
|
|
3067
|
+
} catch {
|
|
3068
|
+
return false;
|
|
3069
|
+
}
|
|
3070
|
+
}
|
|
3071
|
+
function suggestTag(tag) {
|
|
3072
|
+
const near = tag.replace(/_/g, "-");
|
|
3073
|
+
return near !== tag && isLocaleTag(near) ? near : void 0;
|
|
3074
|
+
}
|
|
3075
|
+
function projectLocale(tag, locales) {
|
|
3076
|
+
if (locales.includes(tag)) return tag;
|
|
3077
|
+
const plain = (value) => value.replace(/_/g, "-").toLowerCase();
|
|
3078
|
+
return locales.find((locale) => plain(locale) === plain(tag));
|
|
3079
|
+
}
|
|
3080
|
+
// src/project/doctor.ts
|
|
3412
3081
|
const PREVIEW = 5;
|
|
3413
3082
|
function readRoutingChoice(root, configFile) {
|
|
3414
3083
|
try {
|
|
@@ -3634,7 +3303,23 @@ function preview(keys) {
|
|
|
3634
3303
|
const head = keys.slice(0, PREVIEW).join(", ");
|
|
3635
3304
|
return keys.length > PREVIEW ? `${head}, …` : head;
|
|
3636
3305
|
}
|
|
3637
|
-
// src/
|
|
3306
|
+
// src/cli/commands/doctor.ts
|
|
3307
|
+
async function doctorCommand(cfg) {
|
|
3308
|
+
const result = await doctor(cfg);
|
|
3309
|
+
console.log(`[verbaly] doctor: ${counted(result.entries.length, "check")}`);
|
|
3310
|
+
for (const entry of result.entries) {
|
|
3311
|
+
const line = formatDoctorEntry(entry);
|
|
3312
|
+
if (entry.level === "error") console.error(line);
|
|
3313
|
+
else if (entry.level === "warn") console.warn(line);
|
|
3314
|
+
else console.log(line);
|
|
3315
|
+
}
|
|
3316
|
+
if (result.ok) console.log(`[verbaly] ${formatDoctorHealth(result)} ✓`);
|
|
3317
|
+
else {
|
|
3318
|
+
console.error("[verbaly] doctor found problems");
|
|
3319
|
+
process.exitCode = 1;
|
|
3320
|
+
}
|
|
3321
|
+
}
|
|
3322
|
+
// src/exchange/inline.ts
|
|
3638
3323
|
const OPEN_TAG = /^<([a-zA-Z][a-zA-Z0-9-]*)\s*(\/?)>/;
|
|
3639
3324
|
const BREAK = /^(?:br|wbr)$/;
|
|
3640
3325
|
function messageToInline(text) {
|
|
@@ -3711,7 +3396,7 @@ function parseParts(text, pos, closeTag) {
|
|
|
3711
3396
|
continue;
|
|
3712
3397
|
}
|
|
3713
3398
|
if (text[i] === "{") {
|
|
3714
|
-
const end = matchBrace(text, i);
|
|
3399
|
+
const end = matchBrace$1(text, i);
|
|
3715
3400
|
if (end === -1) {
|
|
3716
3401
|
plain += "{";
|
|
3717
3402
|
i += 1;
|
|
@@ -3780,7 +3465,7 @@ function parseParts(text, pos, closeTag) {
|
|
|
3780
3465
|
closed: false
|
|
3781
3466
|
};
|
|
3782
3467
|
}
|
|
3783
|
-
function matchBrace(text, start) {
|
|
3468
|
+
function matchBrace$1(text, start) {
|
|
3784
3469
|
let depth = 0;
|
|
3785
3470
|
for (let i = start; i < text.length; i++) {
|
|
3786
3471
|
const pair = text[i] + (text[i + 1] ?? "");
|
|
@@ -3850,7 +3535,7 @@ function attr(attrs, name) {
|
|
|
3850
3535
|
const value = new RegExp(`\\b${name}\\s*=\\s*"([^"]*)"`).exec(attrs)?.[1];
|
|
3851
3536
|
return value === void 0 ? void 0 : unescapeXml(value);
|
|
3852
3537
|
}
|
|
3853
|
-
// src/mobile.ts
|
|
3538
|
+
// src/exchange/mobile.ts
|
|
3854
3539
|
function androidValuesDir(locale, sourceLocale) {
|
|
3855
3540
|
if (locale === sourceLocale) return "values";
|
|
3856
3541
|
const parts = locale.split("-");
|
|
@@ -3888,7 +3573,7 @@ function androidText(text) {
|
|
|
3888
3573
|
function iosText(text) {
|
|
3889
3574
|
return text.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\n/g, "\\n").replace(/\t/g, "\\t");
|
|
3890
3575
|
}
|
|
3891
|
-
// src/po.ts
|
|
3576
|
+
// src/exchange/po.ts
|
|
3892
3577
|
function toPo(sourceLocale, locale, entries) {
|
|
3893
3578
|
return [
|
|
3894
3579
|
[
|
|
@@ -3983,7 +3668,7 @@ function poUnquote(text) {
|
|
|
3983
3668
|
return ch;
|
|
3984
3669
|
});
|
|
3985
3670
|
}
|
|
3986
|
-
// src/translate.ts
|
|
3671
|
+
// src/exchange/translate.ts
|
|
3987
3672
|
const RETRY_STATUS = /* @__PURE__ */ new Set([
|
|
3988
3673
|
408,
|
|
3989
3674
|
409,
|
|
@@ -4162,7 +3847,7 @@ function formatTranslateFailures(failed) {
|
|
|
4162
3847
|
async function resolveProvider(cfg, model) {
|
|
4163
3848
|
const configured = cfg.translate.provider;
|
|
4164
3849
|
if (typeof configured === "function") return configured;
|
|
4165
|
-
const { claudeProvider } = await import("./claude-
|
|
3850
|
+
const { claudeProvider } = await import("./claude-BtdaNZEw.js");
|
|
4166
3851
|
return claudeProvider({ model: model ?? cfg.translate.model });
|
|
4167
3852
|
}
|
|
4168
3853
|
function structureMatches(source, translated) {
|
|
@@ -4192,7 +3877,7 @@ function glossaryFor(cfg, locale, messages) {
|
|
|
4192
3877
|
}
|
|
4193
3878
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
4194
3879
|
}
|
|
4195
|
-
// src/exchange.ts
|
|
3880
|
+
// src/exchange/exchange.ts
|
|
4196
3881
|
function isMobileFormat(format) {
|
|
4197
3882
|
return format === "android-xml" || format === "ios-strings";
|
|
4198
3883
|
}
|
|
@@ -4452,7 +4137,715 @@ function csvRows(content) {
|
|
|
4452
4137
|
if (row.some((cell) => cell !== "")) rows.push(row);
|
|
4453
4138
|
return rows;
|
|
4454
4139
|
}
|
|
4455
|
-
// src/
|
|
4140
|
+
// src/cli/commands/export.ts
|
|
4141
|
+
async function exportCommand(cfg, values) {
|
|
4142
|
+
const format = values.format ?? "xliff";
|
|
4143
|
+
if (![
|
|
4144
|
+
"xliff",
|
|
4145
|
+
"csv",
|
|
4146
|
+
"po",
|
|
4147
|
+
"android-xml",
|
|
4148
|
+
"ios-strings"
|
|
4149
|
+
].includes(format)) {
|
|
4150
|
+
console.error(`[verbaly] unknown format "${values.format}", use xliff, csv, po, android-xml or ios-strings`);
|
|
4151
|
+
process.exitCode = 1;
|
|
4152
|
+
return;
|
|
4153
|
+
}
|
|
4154
|
+
if (values.missing && isMobileFormat(format)) {
|
|
4155
|
+
console.error(`[verbaly] --missing is for translator formats (xliff, csv): ${format} already skips untranslated keys so the app falls back to the source locale`);
|
|
4156
|
+
process.exitCode = 1;
|
|
4157
|
+
return;
|
|
4158
|
+
}
|
|
4159
|
+
const registry = await extractProject(cfg);
|
|
4160
|
+
const result = exportCatalogs(cfg, shippedCatalogs(cfg, loadCatalogs(cfg), registry, { newKeys: false }), {
|
|
4161
|
+
locales: csv(values.locales),
|
|
4162
|
+
format,
|
|
4163
|
+
out: values.out,
|
|
4164
|
+
missing: values.missing,
|
|
4165
|
+
origins: isMobileFormat(format) ? void 0 : await collectOrigins(cfg, registry)
|
|
4166
|
+
});
|
|
4167
|
+
if (result.files.length === 0) {
|
|
4168
|
+
console.log("[verbaly] no target locales to export (add locales to your config)");
|
|
4169
|
+
return;
|
|
4170
|
+
}
|
|
4171
|
+
const note = isMobileFormat(result.format) ? "untranslated skipped" : "untranslated";
|
|
4172
|
+
console.log(`[verbaly] exported ${counted(result.files.length, "locale")} (${result.format}) → ${result.dir}`);
|
|
4173
|
+
for (const file of result.files) console.log(` ${file.locale}: ${counted(file.total, "message")} (${file.untranslated} ${note}) → ${file.path}`);
|
|
4174
|
+
}
|
|
4175
|
+
// src/emit/watch.ts
|
|
4176
|
+
const NATIVE_TREE = process.platform === "darwin" || process.platform === "win32";
|
|
4177
|
+
function watchTree(root, options, onFile) {
|
|
4178
|
+
const watchers = /* @__PURE__ */ new Map();
|
|
4179
|
+
const close = (name) => {
|
|
4180
|
+
watchers.get(name)?.close();
|
|
4181
|
+
watchers.delete(name);
|
|
4182
|
+
};
|
|
4183
|
+
const open = (name, recursive, listener) => {
|
|
4184
|
+
const watcher = watch(join(root, name), {
|
|
4185
|
+
recursive,
|
|
4186
|
+
persistent: options.persistent ?? true
|
|
4187
|
+
}, listener);
|
|
4188
|
+
watcher.on("error", (error) => {
|
|
4189
|
+
close(name);
|
|
4190
|
+
console.warn(`[verbaly] stopped watching ${name || "the project"}:`, error);
|
|
4191
|
+
});
|
|
4192
|
+
watchers.set(name, watcher);
|
|
4193
|
+
};
|
|
4194
|
+
if (options.native ?? NATIVE_TREE) open("", true, (_event, file) => {
|
|
4195
|
+
if (file) onFile(file);
|
|
4196
|
+
});
|
|
4197
|
+
else {
|
|
4198
|
+
const sync = (name) => {
|
|
4199
|
+
close(name);
|
|
4200
|
+
if (name !== options.keep && (name === "node_modules" || name.startsWith("."))) return;
|
|
4201
|
+
try {
|
|
4202
|
+
if (!lstatSync(join(root, name)).isDirectory()) return;
|
|
4203
|
+
open(name, true, (_event, file) => {
|
|
4204
|
+
if (file) onFile(`${name}/${file}`);
|
|
4205
|
+
});
|
|
4206
|
+
} catch (error) {
|
|
4207
|
+
if (error.code !== "ENOENT") console.warn(`[verbaly] could not watch ${name}:`, error);
|
|
4208
|
+
}
|
|
4209
|
+
};
|
|
4210
|
+
open("", false, (event, file) => {
|
|
4211
|
+
if (!file) return;
|
|
4212
|
+
if (event === "rename") sync(file);
|
|
4213
|
+
onFile(file);
|
|
4214
|
+
});
|
|
4215
|
+
for (const entry of readdirSync(root, { withFileTypes: true })) if (entry.isDirectory()) sync(entry.name);
|
|
4216
|
+
}
|
|
4217
|
+
return () => {
|
|
4218
|
+
for (const name of [...watchers.keys()]) close(name);
|
|
4219
|
+
};
|
|
4220
|
+
}
|
|
4221
|
+
function watchProject(cfg, run, options = {}) {
|
|
4222
|
+
const catalogDir = relative(cfg.root, cfg.dir).replaceAll("\\", "/");
|
|
4223
|
+
let timer;
|
|
4224
|
+
let running = false;
|
|
4225
|
+
let queued = false;
|
|
4226
|
+
async function refresh() {
|
|
4227
|
+
if (running) {
|
|
4228
|
+
queued = true;
|
|
4229
|
+
return;
|
|
4230
|
+
}
|
|
4231
|
+
running = true;
|
|
4232
|
+
try {
|
|
4233
|
+
await run();
|
|
4234
|
+
} catch (error) {
|
|
4235
|
+
console.warn("[verbaly] watch run failed:", error);
|
|
4236
|
+
} finally {
|
|
4237
|
+
running = false;
|
|
4238
|
+
if (queued) {
|
|
4239
|
+
queued = false;
|
|
4240
|
+
schedule();
|
|
4241
|
+
}
|
|
4242
|
+
}
|
|
4243
|
+
}
|
|
4244
|
+
function schedule() {
|
|
4245
|
+
clearTimeout(timer);
|
|
4246
|
+
timer = setTimeout(() => void refresh(), options.debounce ?? 150);
|
|
4247
|
+
}
|
|
4248
|
+
const close = watchTree(cfg.root, {}, (filename) => {
|
|
4249
|
+
if (!filename) return;
|
|
4250
|
+
const file = filename.replaceAll("\\", "/");
|
|
4251
|
+
if (file.includes("node_modules/") || file.endsWith(".d.ts")) return;
|
|
4252
|
+
if (catalogDir && file.startsWith(`${catalogDir}/`)) return;
|
|
4253
|
+
if (SOURCE_FILE_RE.test(file)) schedule();
|
|
4254
|
+
});
|
|
4255
|
+
return () => {
|
|
4256
|
+
clearTimeout(timer);
|
|
4257
|
+
close();
|
|
4258
|
+
};
|
|
4259
|
+
}
|
|
4260
|
+
// src/cli/commands/extract.ts
|
|
4261
|
+
async function extractCommand(cfg, values) {
|
|
4262
|
+
const dryRun = values["dry-run"];
|
|
4263
|
+
if (values.watch && (dryRun || values.prune)) {
|
|
4264
|
+
console.error("[verbaly] --watch runs alone: prune is a deliberate one-shot action and dry-run writes nothing");
|
|
4265
|
+
process.exitCode = 1;
|
|
4266
|
+
return;
|
|
4267
|
+
}
|
|
4268
|
+
const reporter = values.watch ? createDevReporter(cfg.root, (line) => console.warn(` ${line}`)) : void 0;
|
|
4269
|
+
async function runExtract() {
|
|
4270
|
+
const result = await syncProject(cfg, {
|
|
4271
|
+
prune: values.prune,
|
|
4272
|
+
dryRun
|
|
4273
|
+
});
|
|
4274
|
+
if (result.pruneBlocked) {
|
|
4275
|
+
const unread = result.registry.parseErrors().length;
|
|
4276
|
+
console.warn(` prune skipped: an unparsed file may read any key (${counted(unread, "file")} below), so it waits until every file parses`);
|
|
4277
|
+
}
|
|
4278
|
+
for (const [locale, keys] of Object.entries(result.pruned)) console.log(dryRun ? ` ${locale}: would prune ${keys.length}: ${keys.join(", ")}` : ` ${locale}: -${keys.length} pruned`);
|
|
4279
|
+
const origin = result.inCode === result.messages ? "" : ` (${result.inCode} in code)`;
|
|
4280
|
+
console.log(`[verbaly] ${counted(result.messages, "message")}${origin} · locales: ${cfg.locales.join(", ")}${dryRun ? " (dry run, nothing written)" : ""}`);
|
|
4281
|
+
for (const [locale, keys] of Object.entries(result.added)) console.log(` ${locale}: ${dryRun ? `would add ${keys.length}` : `+${keys.length}`}`);
|
|
4282
|
+
const warnings = result.findings.filter((finding) => {
|
|
4283
|
+
if (finding.kind !== "replaced" && finding.kind !== "lock") return true;
|
|
4284
|
+
console.log(` ${formatFinding(finding, cfg.root)}`);
|
|
4285
|
+
return false;
|
|
4286
|
+
});
|
|
4287
|
+
if (reporter) reporter.report("extract", warnings);
|
|
4288
|
+
else for (const finding of warnings) console.warn(` ${formatFinding(finding, cfg.root)}`);
|
|
4289
|
+
if (result.stateProblem) console.warn(` ${result.stateProblem}, so drafts and outdated translations were not updated`);
|
|
4290
|
+
}
|
|
4291
|
+
await runExtract();
|
|
4292
|
+
if (values.watch) {
|
|
4293
|
+
watchProject(cfg, runExtract);
|
|
4294
|
+
console.log("[verbaly] watching for source changes (ctrl+c to stop)");
|
|
4295
|
+
}
|
|
4296
|
+
}
|
|
4297
|
+
// src/cli/commands/import.ts
|
|
4298
|
+
async function importCommand(cfg, values, positionals) {
|
|
4299
|
+
const files = positionals.slice(1);
|
|
4300
|
+
if (files.length === 0) {
|
|
4301
|
+
console.error("[verbaly] import needs at least one file: verbaly import verbaly-export/es.xlf");
|
|
4302
|
+
process.exitCode = 1;
|
|
4303
|
+
return;
|
|
4304
|
+
}
|
|
4305
|
+
if (!values["dry-run"]) loadState(cfg);
|
|
4306
|
+
const registry = await extractProject(cfg);
|
|
4307
|
+
const catalogs = shippedCatalogs(cfg, loadCatalogs(cfg), registry, { newKeys: false });
|
|
4308
|
+
const result = importCatalogs(cfg, catalogs, files, {
|
|
4309
|
+
locale: values.locale,
|
|
4310
|
+
overwrite: values.overwrite,
|
|
4311
|
+
dryRun: values["dry-run"]
|
|
4312
|
+
});
|
|
4313
|
+
for (const { file, from, to } of result.mapped) console.log(` ${file}: "${from}" read as ${to}`);
|
|
4314
|
+
for (const { file, locale, reason } of result.unmatched) {
|
|
4315
|
+
if (reason === "undeclared") {
|
|
4316
|
+
console.warn(` ${file}: "${locale}" is not one of this project's locales (${cfg.locales.join(", ")}), so nothing was imported from it`);
|
|
4317
|
+
console.warn(` fix: add ${locale} to locales in your verbaly config, or pass --locale with one of them`);
|
|
4318
|
+
} else {
|
|
4319
|
+
console.warn(` ${file}: "${locale}" is not a locale tag, so nothing was imported from it`);
|
|
4320
|
+
console.warn(" fix: pass --locale with the tag it stands for, like pt-BR");
|
|
4321
|
+
}
|
|
4322
|
+
process.exitCode = 1;
|
|
4323
|
+
}
|
|
4324
|
+
const writes = [];
|
|
4325
|
+
for (const [locale, keys] of Object.entries(result.imported)) {
|
|
4326
|
+
if (!values["dry-run"]) {
|
|
4327
|
+
const catalog = catalogs[locale] ?? {};
|
|
4328
|
+
writeCatalog(cfg, locale, catalog);
|
|
4329
|
+
const seen = result.sources[locale] ?? {};
|
|
4330
|
+
const entries = keys.map((key) => ({
|
|
4331
|
+
key,
|
|
4332
|
+
text: catalog[key],
|
|
4333
|
+
source: seen[key]
|
|
4334
|
+
}));
|
|
4335
|
+
writes.push({
|
|
4336
|
+
locale,
|
|
4337
|
+
entries,
|
|
4338
|
+
draft: values.draft === true
|
|
4339
|
+
});
|
|
4340
|
+
}
|
|
4341
|
+
const verb = values["dry-run"] ? "would import" : "imported";
|
|
4342
|
+
console.log(` ${locale}: +${keys.length} ${verb}${values.draft ? " (draft)" : ""}`);
|
|
4343
|
+
}
|
|
4344
|
+
const lockBefore = stateFile(cfg);
|
|
4345
|
+
if (writes.length > 0) recordTranslations(cfg, catalogs[cfg.sourceLocale] ?? {}, writes);
|
|
4346
|
+
sayLockNews(cfg, lockBefore);
|
|
4347
|
+
for (const [locale, keys] of Object.entries(result.skipped)) console.log(` ${locale}: ${keys.length} already translated, kept (use --overwrite to replace)`);
|
|
4348
|
+
for (const [locale, keys] of Object.entries(result.rejected)) console.warn(` ${locale}: ${keys.length} rejected (params/tags not preserved): ${keys.join(", ")}`);
|
|
4349
|
+
for (const [locale, keys] of Object.entries(result.unknown)) console.warn(` ${locale}: ${counted(keys.length, "unknown key")} ignored (not in the source catalog): ${keys.join(", ")}`);
|
|
4350
|
+
if (Object.keys(result.imported).length === 0 && result.unmatched.length === 0) console.log("[verbaly] nothing to import ✓");
|
|
4351
|
+
}
|
|
4352
|
+
// src/catalog/migrate.ts
|
|
4353
|
+
const KNOWN = [
|
|
4354
|
+
"i18next",
|
|
4355
|
+
"react-i18next",
|
|
4356
|
+
"vue-i18n",
|
|
4357
|
+
"react-intl",
|
|
4358
|
+
"next-intl",
|
|
4359
|
+
"svelte-i18n"
|
|
4360
|
+
];
|
|
4361
|
+
function detectLibraries(root) {
|
|
4362
|
+
const path = join(root, "package.json");
|
|
4363
|
+
if (!existsSync(path)) return [];
|
|
4364
|
+
let manifest;
|
|
4365
|
+
try {
|
|
4366
|
+
manifest = JSON.parse(readFileSync(path, "utf8"));
|
|
4367
|
+
} catch {
|
|
4368
|
+
return [];
|
|
4369
|
+
}
|
|
4370
|
+
const deps = {
|
|
4371
|
+
...manifest.dependencies,
|
|
4372
|
+
...manifest.devDependencies
|
|
4373
|
+
};
|
|
4374
|
+
return KNOWN.filter((name) => deps[name] !== void 0);
|
|
4375
|
+
}
|
|
4376
|
+
const PLAIN = /\{\{\s*([A-Za-z_$][\w$]*)\s*\}\}/g;
|
|
4377
|
+
const FORMATTED = /\{\{\s*-?\s*[A-Za-z_$][\w$]*\s*,[^}]*\}\}/;
|
|
4378
|
+
const UNESCAPED = /\{\{\s*-\s*[A-Za-z_$][\w$]*\s*\}\}/;
|
|
4379
|
+
const NESTED = /\$t\(/;
|
|
4380
|
+
const DOUBLE = /\{\{[^{}]*\}\}/;
|
|
4381
|
+
const DOUBLES = new RegExp(DOUBLE.source, "g");
|
|
4382
|
+
const ONE_PLAIN = new RegExp(`^${PLAIN.source}$`);
|
|
4383
|
+
const NAME = /^\s*([A-Za-z_$][\w$]*)\s*$/;
|
|
4384
|
+
const CATEGORIES = [
|
|
4385
|
+
"zero",
|
|
4386
|
+
"one",
|
|
4387
|
+
"two",
|
|
4388
|
+
"few",
|
|
4389
|
+
"many",
|
|
4390
|
+
"other"
|
|
4391
|
+
];
|
|
4392
|
+
const SUFFIX = new RegExp(`^(.*)_(${[...CATEGORIES, "plural"].join("|")})$`);
|
|
4393
|
+
function i18nextProblem(text) {
|
|
4394
|
+
if (NESTED.test(text)) return "uses $t() nesting, which has no direct equivalent";
|
|
4395
|
+
if (UNESCAPED.test(text)) return "uses {{- name}}, so decide whether the message is rich";
|
|
4396
|
+
if (FORMATTED.test(text)) return "uses an i18next format, which needs the matching Verbaly one";
|
|
4397
|
+
for (const [double] of text.matchAll(DOUBLES)) if (!ONE_PLAIN.test(double)) return "uses {{…}} with more than a name, which needs a Verbaly param";
|
|
4398
|
+
}
|
|
4399
|
+
function convertBraces(text) {
|
|
4400
|
+
let out = "";
|
|
4401
|
+
let last = 0;
|
|
4402
|
+
for (const match of text.matchAll(PLAIN)) {
|
|
4403
|
+
out += escapeBraces(text.slice(last, match.index)) + `{${match[1]}}`;
|
|
4404
|
+
last = match.index + match[0].length;
|
|
4405
|
+
}
|
|
4406
|
+
return out + escapeBraces(text.slice(last));
|
|
4407
|
+
}
|
|
4408
|
+
function escapeBraces(text) {
|
|
4409
|
+
return text.replace(/[{}]/g, (brace) => brace + brace);
|
|
4410
|
+
}
|
|
4411
|
+
function toVariant(text) {
|
|
4412
|
+
let out = "";
|
|
4413
|
+
let i = 0;
|
|
4414
|
+
while (i < text.length) {
|
|
4415
|
+
const ch = text[i];
|
|
4416
|
+
if ((ch === "{" || ch === "}") && text[i + 1] === ch) {
|
|
4417
|
+
out += ch + ch;
|
|
4418
|
+
i += 2;
|
|
4419
|
+
} else if (ch === "{") {
|
|
4420
|
+
const close = text.indexOf("}", i);
|
|
4421
|
+
const name = close < 0 ? void 0 : NAME.exec(text.slice(i + 1, close))?.[1];
|
|
4422
|
+
if (name === void 0) return void 0;
|
|
4423
|
+
out += name === "count" ? "#" : `{${name}}`;
|
|
4424
|
+
i = close + 1;
|
|
4425
|
+
} else {
|
|
4426
|
+
out += ch === "#" || ch === "|" || ch === "}" ? ch + ch : ch;
|
|
4427
|
+
i += 1;
|
|
4428
|
+
}
|
|
4429
|
+
}
|
|
4430
|
+
return out;
|
|
4431
|
+
}
|
|
4432
|
+
function order(a, b) {
|
|
4433
|
+
return CATEGORIES.indexOf(a) - CATEGORIES.indexOf(b);
|
|
4434
|
+
}
|
|
4435
|
+
function mergePlurals(locale, catalog, out, plurals, skipped, fromI18next) {
|
|
4436
|
+
const groups = /* @__PURE__ */ new Map();
|
|
4437
|
+
const legacy = /* @__PURE__ */ new Set();
|
|
4438
|
+
for (const [key, value] of Object.entries(catalog)) {
|
|
4439
|
+
const match = SUFFIX.exec(key);
|
|
4440
|
+
if (!match || typeof value !== "string") continue;
|
|
4441
|
+
const [, base, suffix] = match;
|
|
4442
|
+
if (suffix === "plural") legacy.add(base);
|
|
4443
|
+
const category = suffix === "plural" ? "other" : suffix;
|
|
4444
|
+
if (!groups.has(base)) groups.set(base, /* @__PURE__ */ new Map());
|
|
4445
|
+
groups.get(base).set(category, {
|
|
4446
|
+
key,
|
|
4447
|
+
value
|
|
4448
|
+
});
|
|
4449
|
+
}
|
|
4450
|
+
for (const [base, forms] of groups) {
|
|
4451
|
+
const bare = catalog[base];
|
|
4452
|
+
if (legacy.has(base) && typeof bare === "string" && !forms.has("one")) forms.set("one", {
|
|
4453
|
+
key: base,
|
|
4454
|
+
value: bare
|
|
4455
|
+
});
|
|
4456
|
+
else if (bare !== void 0) {
|
|
4457
|
+
skipped.push({
|
|
4458
|
+
locale,
|
|
4459
|
+
key: base,
|
|
4460
|
+
reason: `"${base}" already exists, so merging would overwrite it`
|
|
4461
|
+
});
|
|
4462
|
+
continue;
|
|
4463
|
+
}
|
|
4464
|
+
if (!forms.has("other")) {
|
|
4465
|
+
skipped.push({
|
|
4466
|
+
locale,
|
|
4467
|
+
key: base,
|
|
4468
|
+
reason: "no _other form, so the block would have no catch-all"
|
|
4469
|
+
});
|
|
4470
|
+
continue;
|
|
4471
|
+
}
|
|
4472
|
+
if (forms.size === 1) {
|
|
4473
|
+
skipped.push({
|
|
4474
|
+
locale,
|
|
4475
|
+
key: base,
|
|
4476
|
+
reason: "only a plural form, so add the singular before merging"
|
|
4477
|
+
});
|
|
4478
|
+
continue;
|
|
4479
|
+
}
|
|
4480
|
+
const sorted = [...forms.entries()].sort((a, b) => order(a[0], b[0]));
|
|
4481
|
+
const cases = [];
|
|
4482
|
+
let problem;
|
|
4483
|
+
for (const [category, form] of sorted) {
|
|
4484
|
+
problem = fromI18next ? i18nextProblem(form.value) : void 0;
|
|
4485
|
+
const body = problem ? void 0 : toVariant(fromI18next ? convertBraces(form.value) : form.value);
|
|
4486
|
+
if (body === void 0) {
|
|
4487
|
+
problem ??= "a form holds more than a name in braces, so merge it by hand";
|
|
4488
|
+
break;
|
|
4489
|
+
}
|
|
4490
|
+
cases.push(`${category}: ${body}`);
|
|
4491
|
+
}
|
|
4492
|
+
if (problem) {
|
|
4493
|
+
skipped.push({
|
|
4494
|
+
locale,
|
|
4495
|
+
key: base,
|
|
4496
|
+
reason: problem
|
|
4497
|
+
});
|
|
4498
|
+
continue;
|
|
4499
|
+
}
|
|
4500
|
+
const merged = `{count | ${cases.join(" | ")}}`;
|
|
4501
|
+
for (const [, form] of sorted) delete out[form.key];
|
|
4502
|
+
out[base] = merged;
|
|
4503
|
+
plurals.push({
|
|
4504
|
+
locale,
|
|
4505
|
+
key: base,
|
|
4506
|
+
from: sorted.map(([, form]) => form.key),
|
|
4507
|
+
after: merged
|
|
4508
|
+
});
|
|
4509
|
+
}
|
|
4510
|
+
}
|
|
4511
|
+
function migrateCatalogs(cfg, options = {}) {
|
|
4512
|
+
const braces = [];
|
|
4513
|
+
const plurals = [];
|
|
4514
|
+
const skipped = [];
|
|
4515
|
+
const written = [];
|
|
4516
|
+
const state = loadState(cfg);
|
|
4517
|
+
const done = new Set(state.migrated ?? []);
|
|
4518
|
+
const catalogs = new Map(cfg.locales.map((locale) => [locale, readCatalog(cfg, locale)]));
|
|
4519
|
+
const pending = cfg.locales.filter((locale) => !done.has(locale));
|
|
4520
|
+
const fromI18next = pending.some((locale) => Object.values(catalogs.get(locale)).some((value) => typeof value === "string" && (DOUBLE.test(value) || NESTED.test(value))));
|
|
4521
|
+
for (const locale of cfg.locales) {
|
|
4522
|
+
const catalog = catalogs.get(locale);
|
|
4523
|
+
const out = Object.assign(emptyCatalog(), catalog);
|
|
4524
|
+
const convert = fromI18next && !done.has(locale);
|
|
4525
|
+
for (const [key, value] of Object.entries(catalog)) {
|
|
4526
|
+
if (!convert || typeof value !== "string") continue;
|
|
4527
|
+
const problem = i18nextProblem(value);
|
|
4528
|
+
if (problem) {
|
|
4529
|
+
skipped.push({
|
|
4530
|
+
locale,
|
|
4531
|
+
key,
|
|
4532
|
+
reason: problem
|
|
4533
|
+
});
|
|
4534
|
+
continue;
|
|
4535
|
+
}
|
|
4536
|
+
const after = convertBraces(value);
|
|
4537
|
+
if (after !== value) {
|
|
4538
|
+
braces.push({
|
|
4539
|
+
locale,
|
|
4540
|
+
key,
|
|
4541
|
+
before: value,
|
|
4542
|
+
after
|
|
4543
|
+
});
|
|
4544
|
+
out[key] = after;
|
|
4545
|
+
}
|
|
4546
|
+
}
|
|
4547
|
+
if (options.plurals) mergePlurals(locale, catalog, out, plurals, skipped, convert);
|
|
4548
|
+
if ((braces.some((b) => b.locale === locale) || plurals.some((p) => p.locale === locale)) && options.write) {
|
|
4549
|
+
writeCatalog(cfg, locale, out);
|
|
4550
|
+
written.push(locale);
|
|
4551
|
+
}
|
|
4552
|
+
}
|
|
4553
|
+
if (options.write && fromI18next) {
|
|
4554
|
+
const converted = pending.filter((locale) => existsSync(catalogPath(cfg, locale)));
|
|
4555
|
+
if (converted.length) saveState(cfg, {
|
|
4556
|
+
...state,
|
|
4557
|
+
migrated: [...done, ...converted]
|
|
4558
|
+
});
|
|
4559
|
+
}
|
|
4560
|
+
const remembered = cfg.locales.filter((locale) => done.has(locale));
|
|
4561
|
+
return {
|
|
4562
|
+
detected: detectLibraries(cfg.root),
|
|
4563
|
+
braces,
|
|
4564
|
+
plurals,
|
|
4565
|
+
skipped,
|
|
4566
|
+
written,
|
|
4567
|
+
remembered
|
|
4568
|
+
};
|
|
4569
|
+
}
|
|
4570
|
+
// src/project/init.ts
|
|
4571
|
+
const CATALOG_DIRS = [
|
|
4572
|
+
"locales",
|
|
4573
|
+
"src/locales",
|
|
4574
|
+
"src/i18n/locales",
|
|
4575
|
+
"src/i18n",
|
|
4576
|
+
"i18n",
|
|
4577
|
+
"lang",
|
|
4578
|
+
"src/lang",
|
|
4579
|
+
"translations",
|
|
4580
|
+
"src/translations",
|
|
4581
|
+
"messages"
|
|
4582
|
+
];
|
|
4583
|
+
function existingCatalogs(root) {
|
|
4584
|
+
return CATALOG_DIRS.find((dir) => {
|
|
4585
|
+
try {
|
|
4586
|
+
return readdirSync(join(root, dir)).some((file) => file.endsWith(".json") && isLocaleTag(file.slice(0, -5)));
|
|
4587
|
+
} catch {
|
|
4588
|
+
return false;
|
|
4589
|
+
}
|
|
4590
|
+
});
|
|
4591
|
+
}
|
|
4592
|
+
function configSource(options, typescript) {
|
|
4593
|
+
const fields = [` sourceLocale: '${options.sourceLocale ?? "en"}',`];
|
|
4594
|
+
if (options.locales?.length) fields.push(` locales: [${options.locales.map((l) => `'${l}'`).join(", ")}],`);
|
|
4595
|
+
if (options.dir) fields.push(` dir: '${options.dir}',`);
|
|
4596
|
+
const body = `export default {\n${fields.join("\n")}\n}`;
|
|
4597
|
+
if (typescript) return `import type { VerbalyConfig } from '@verbaly/compiler';\n\n${body} satisfies VerbalyConfig;\n`;
|
|
4598
|
+
return `/** @type {import('@verbaly/compiler').VerbalyConfig} */\n${body};\n`;
|
|
4599
|
+
}
|
|
4600
|
+
async function init(input = {}) {
|
|
4601
|
+
const root = input.root ?? process.cwd();
|
|
4602
|
+
const created = [];
|
|
4603
|
+
const skipped = [];
|
|
4604
|
+
const renamed = [];
|
|
4605
|
+
const refused = [];
|
|
4606
|
+
const typed = input.locales?.flatMap((locale) => {
|
|
4607
|
+
if (isLocaleTag(locale)) return [locale];
|
|
4608
|
+
const near = suggestTag(locale);
|
|
4609
|
+
if (near) renamed.push({
|
|
4610
|
+
from: locale,
|
|
4611
|
+
to: near
|
|
4612
|
+
});
|
|
4613
|
+
else refused.push(locale);
|
|
4614
|
+
return near ? [near] : [];
|
|
4615
|
+
});
|
|
4616
|
+
const locales = typed && [...new Set(typed)];
|
|
4617
|
+
let sourceLocale = input.sourceLocale;
|
|
4618
|
+
if (sourceLocale !== void 0 && !isLocaleTag(sourceLocale)) {
|
|
4619
|
+
const near = suggestTag(sourceLocale);
|
|
4620
|
+
if (!near) throw new Error(`[verbaly] "${sourceLocale}" is not a locale tag: pass --source with one like en or pt-BR`);
|
|
4621
|
+
renamed.push({
|
|
4622
|
+
from: sourceLocale,
|
|
4623
|
+
to: near
|
|
4624
|
+
});
|
|
4625
|
+
sourceLocale = near;
|
|
4626
|
+
}
|
|
4627
|
+
const options = {
|
|
4628
|
+
...input,
|
|
4629
|
+
locales,
|
|
4630
|
+
sourceLocale
|
|
4631
|
+
};
|
|
4632
|
+
const existing = findConfigFile(root);
|
|
4633
|
+
const typescript = existsSync(join(root, "tsconfig.json"));
|
|
4634
|
+
const configFile = existing ?? (typescript ? "verbaly.config.ts" : "verbaly.config.mjs");
|
|
4635
|
+
const found = existing || options.dir ? void 0 : existingCatalogs(root);
|
|
4636
|
+
if (existing) skipped.push(existing);
|
|
4637
|
+
else {
|
|
4638
|
+
const dir = found === "locales" ? void 0 : found;
|
|
4639
|
+
writeFileSync(join(root, configFile), configSource({
|
|
4640
|
+
...options,
|
|
4641
|
+
dir: options.dir ?? dir
|
|
4642
|
+
}, typescript));
|
|
4643
|
+
created.push(configFile);
|
|
4644
|
+
}
|
|
4645
|
+
const fromFile = existing ? await loadConfigFile(root) : {};
|
|
4646
|
+
const scaffold = {
|
|
4647
|
+
dir: options.dir ?? fromFile.dir ?? found,
|
|
4648
|
+
sourceLocale: options.sourceLocale ?? fromFile.sourceLocale,
|
|
4649
|
+
locales: options.locales ?? fromFile.locales
|
|
4650
|
+
};
|
|
4651
|
+
const dir = join(root, scaffold.dir ?? "locales");
|
|
4652
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
4653
|
+
for (const locale of /* @__PURE__ */ new Set([scaffold.sourceLocale ?? "en", ...scaffold.locales ?? []])) {
|
|
4654
|
+
const file = join(dir, `${locale}.json`);
|
|
4655
|
+
const label = relative(root, file).replaceAll("\\", "/");
|
|
4656
|
+
if (existsSync(file)) skipped.push(label);
|
|
4657
|
+
else {
|
|
4658
|
+
writeFileSync(file, "{}\n");
|
|
4659
|
+
created.push(label);
|
|
4660
|
+
}
|
|
4661
|
+
}
|
|
4662
|
+
const host = detectHost(root);
|
|
4663
|
+
const deps = readDependencies(root);
|
|
4664
|
+
const missing = host?.install.filter((pkg) => !deps[pkg]) ?? [];
|
|
4665
|
+
const next = host ? [...missing.length ? [installCommand(root, missing)] : [], host.wire] : ["run \"verbaly extract\" after writing your first t`…` message"];
|
|
4666
|
+
const others = detectLibraries(root);
|
|
4667
|
+
if (found && others.length) next.push(`port the ${others.join(" and ")} catalogs: npx verbaly migrate reports, --write applies`);
|
|
4668
|
+
return {
|
|
4669
|
+
created,
|
|
4670
|
+
skipped,
|
|
4671
|
+
host: host?.name,
|
|
4672
|
+
configFile,
|
|
4673
|
+
next,
|
|
4674
|
+
renamed,
|
|
4675
|
+
refused,
|
|
4676
|
+
found
|
|
4677
|
+
};
|
|
4678
|
+
}
|
|
4679
|
+
// src/cli/commands/init.ts
|
|
4680
|
+
async function initCommand(values) {
|
|
4681
|
+
const result = await init({
|
|
4682
|
+
root: values.root,
|
|
4683
|
+
dir: values.dir,
|
|
4684
|
+
sourceLocale: values.source,
|
|
4685
|
+
locales: csv(values.locales)
|
|
4686
|
+
});
|
|
4687
|
+
if (result.created.length) console.log(`[verbaly] created: ${result.created.join(", ")}`);
|
|
4688
|
+
if (result.skipped.length) console.log(` kept (already there): ${result.skipped.join(", ")}`);
|
|
4689
|
+
for (const { from, to } of result.renamed) console.log(` wrote ${to} for ${from}, since a locale tag takes a hyphen`);
|
|
4690
|
+
for (const locale of result.refused) console.warn(` left out "${locale}": it is not a locale tag, use one like es or pt-BR`);
|
|
4691
|
+
if (result.found) console.log(` catalogs: ${result.found}, kept where they already are`);
|
|
4692
|
+
if (result.host) console.log(` detected: ${result.host}`);
|
|
4693
|
+
console.log([" next steps:", ...result.next.map((step, i) => ` ${i + 1}. ${step}`)].join("\n"));
|
|
4694
|
+
}
|
|
4695
|
+
// src/cli/commands/migrate.ts
|
|
4696
|
+
async function migrateCommand(cfg, values) {
|
|
4697
|
+
const lockBefore = stateFile(cfg);
|
|
4698
|
+
const result = migrateCatalogs(cfg, {
|
|
4699
|
+
write: values.write,
|
|
4700
|
+
plurals: values.plurals
|
|
4701
|
+
});
|
|
4702
|
+
const from = result.detected.length ? result.detected.join(", ") : "no known i18n library";
|
|
4703
|
+
const changes = result.braces.length + result.plurals.length;
|
|
4704
|
+
const before = result.remembered.length ? `, ${counted(result.remembered.length, "language")} converted before` : "";
|
|
4705
|
+
if (changes === 0 && result.skipped.length === 0) {
|
|
4706
|
+
console.log(`[verbaly] catalogs need nothing (${from}${before}) ✓`);
|
|
4707
|
+
return;
|
|
4708
|
+
}
|
|
4709
|
+
const verb = values.write ? "ported" : "would port";
|
|
4710
|
+
const note = values.write ? "" : " (report only, use --write to apply)";
|
|
4711
|
+
console.log(`[verbaly] ${verb} ${counted(changes, "message")} from ${from}${before}${note}`);
|
|
4712
|
+
for (const entry of result.braces) console.log(` ${entry.locale} ${entry.key} ${entry.before} → ${entry.after}`);
|
|
4713
|
+
for (const entry of result.plurals) console.log(` ${entry.locale} ${entry.key} ${entry.from.join(" + ")} → ${entry.after}`);
|
|
4714
|
+
if (!values.plurals && changes > 0) console.log(" --plurals also merges _one/_other into one message with variants");
|
|
4715
|
+
if (result.skipped.length > 0) {
|
|
4716
|
+
console.log(" needs a human:");
|
|
4717
|
+
for (const entry of result.skipped) console.log(` ${entry.locale} ${entry.key} ${entry.reason}`);
|
|
4718
|
+
}
|
|
4719
|
+
if (values.write && result.braces.length > 0) console.log(` ${STATE_FILE} remembers the converted languages, so a later run never reads them as i18next again`);
|
|
4720
|
+
sayLockNews(cfg, lockBefore);
|
|
4721
|
+
if (values.write) console.log(" next: run verbaly check");
|
|
4722
|
+
}
|
|
4723
|
+
// src/catalog/pseudo.ts
|
|
4724
|
+
const ACCENTS = {
|
|
4725
|
+
a: "á",
|
|
4726
|
+
b: "ƀ",
|
|
4727
|
+
c: "ç",
|
|
4728
|
+
d: "đ",
|
|
4729
|
+
e: "é",
|
|
4730
|
+
f: "ƒ",
|
|
4731
|
+
g: "ğ",
|
|
4732
|
+
h: "ĥ",
|
|
4733
|
+
i: "í",
|
|
4734
|
+
j: "ĵ",
|
|
4735
|
+
k: "ķ",
|
|
4736
|
+
l: "ĺ",
|
|
4737
|
+
m: "ɱ",
|
|
4738
|
+
n: "ñ",
|
|
4739
|
+
o: "ó",
|
|
4740
|
+
p: "þ",
|
|
4741
|
+
q: "ǫ",
|
|
4742
|
+
r: "ŕ",
|
|
4743
|
+
s: "š",
|
|
4744
|
+
t: "ţ",
|
|
4745
|
+
u: "ú",
|
|
4746
|
+
v: "ṽ",
|
|
4747
|
+
w: "ŵ",
|
|
4748
|
+
x: "ẋ",
|
|
4749
|
+
y: "ý",
|
|
4750
|
+
z: "ž",
|
|
4751
|
+
A: "Á",
|
|
4752
|
+
B: "Ɓ",
|
|
4753
|
+
C: "Ç",
|
|
4754
|
+
D: "Đ",
|
|
4755
|
+
E: "É",
|
|
4756
|
+
F: "Ƒ",
|
|
4757
|
+
G: "Ğ",
|
|
4758
|
+
H: "Ĥ",
|
|
4759
|
+
I: "Í",
|
|
4760
|
+
J: "Ĵ",
|
|
4761
|
+
K: "Ķ",
|
|
4762
|
+
L: "Ĺ",
|
|
4763
|
+
M: "Ḿ",
|
|
4764
|
+
N: "Ñ",
|
|
4765
|
+
O: "Ó",
|
|
4766
|
+
P: "Þ",
|
|
4767
|
+
Q: "Ǫ",
|
|
4768
|
+
R: "Ŕ",
|
|
4769
|
+
S: "Š",
|
|
4770
|
+
T: "Ţ",
|
|
4771
|
+
U: "Ú",
|
|
4772
|
+
V: "Ṽ",
|
|
4773
|
+
W: "Ŵ",
|
|
4774
|
+
X: "Ẍ",
|
|
4775
|
+
Y: "Ý",
|
|
4776
|
+
Z: "Ž"
|
|
4777
|
+
};
|
|
4778
|
+
const TAG_AT = /<\/?[a-zA-Z][\w-]*\/?>/y;
|
|
4779
|
+
function pseudoLocalize(message) {
|
|
4780
|
+
let out = "";
|
|
4781
|
+
let letters = 0;
|
|
4782
|
+
let i = 0;
|
|
4783
|
+
while (i < message.length) {
|
|
4784
|
+
const two = message.slice(i, i + 2);
|
|
4785
|
+
if (two === "{{" || two === "}}" || two === "||" || two === "##") {
|
|
4786
|
+
out += two;
|
|
4787
|
+
i += 2;
|
|
4788
|
+
continue;
|
|
4789
|
+
}
|
|
4790
|
+
const ch = message[i];
|
|
4791
|
+
if (ch === "{") {
|
|
4792
|
+
const end = matchBrace(message, i);
|
|
4793
|
+
out += message.slice(i, end);
|
|
4794
|
+
i = end;
|
|
4795
|
+
continue;
|
|
4796
|
+
}
|
|
4797
|
+
if (ch === "<") {
|
|
4798
|
+
TAG_AT.lastIndex = i;
|
|
4799
|
+
const m = TAG_AT.exec(message);
|
|
4800
|
+
if (m) {
|
|
4801
|
+
out += m[0];
|
|
4802
|
+
i += m[0].length;
|
|
4803
|
+
continue;
|
|
4804
|
+
}
|
|
4805
|
+
}
|
|
4806
|
+
const mapped = ACCENTS[ch];
|
|
4807
|
+
if (mapped) {
|
|
4808
|
+
out += mapped;
|
|
4809
|
+
letters += 1;
|
|
4810
|
+
} else out += ch;
|
|
4811
|
+
i += 1;
|
|
4812
|
+
}
|
|
4813
|
+
const pad = "~".repeat(Math.ceil(letters / 3));
|
|
4814
|
+
return `⟦${out}${pad ? " " + pad : ""}⟧`;
|
|
4815
|
+
}
|
|
4816
|
+
function matchBrace(message, start) {
|
|
4817
|
+
let depth = 0;
|
|
4818
|
+
for (let i = start; i < message.length; i++) {
|
|
4819
|
+
const two = message.slice(i, i + 2);
|
|
4820
|
+
if (two === "{{" || two === "}}") {
|
|
4821
|
+
i += 1;
|
|
4822
|
+
continue;
|
|
4823
|
+
}
|
|
4824
|
+
const ch = message[i];
|
|
4825
|
+
if (ch === "{") depth += 1;
|
|
4826
|
+
else if (ch === "}") {
|
|
4827
|
+
depth -= 1;
|
|
4828
|
+
if (depth === 0) return i + 1;
|
|
4829
|
+
}
|
|
4830
|
+
}
|
|
4831
|
+
return message.length;
|
|
4832
|
+
}
|
|
4833
|
+
function pseudoCatalogs(cfg, catalogs, locale = PSEUDO_LOCALE) {
|
|
4834
|
+
const source = catalogs[cfg.sourceLocale] ?? {};
|
|
4835
|
+
const target = emptyCatalog();
|
|
4836
|
+
for (const [key, msg] of Object.entries(source)) target[key] = msg ? pseudoLocalize(msg) : "";
|
|
4837
|
+
catalogs[locale] = target;
|
|
4838
|
+
return Object.keys(target).filter((key) => target[key]);
|
|
4839
|
+
}
|
|
4840
|
+
// src/cli/commands/pseudo.ts
|
|
4841
|
+
async function pseudoCommand(cfg, values) {
|
|
4842
|
+
const catalogs = shippedCatalogs(cfg, loadCatalogs(cfg), await extractProject(cfg), { newKeys: false });
|
|
4843
|
+
const locale = values.locale ?? "en-XA";
|
|
4844
|
+
const keys = pseudoCatalogs(cfg, catalogs, locale);
|
|
4845
|
+
writeCatalog(cfg, locale, catalogs[locale] ?? {});
|
|
4846
|
+
console.log(`[verbaly] ${counted(keys.length, "message")} pseudo-localized → ${locale}`);
|
|
4847
|
+
}
|
|
4848
|
+
// src/emit/render.ts
|
|
4456
4849
|
function localeInstance(catalogs, locale, sourceLocale) {
|
|
4457
4850
|
return createVerbaly({
|
|
4458
4851
|
locale,
|
|
@@ -4901,92 +5294,144 @@ function escapeAttr(text) {
|
|
|
4901
5294
|
function decodeEntities(text) {
|
|
4902
5295
|
return text.replace(/"/g, "\"").replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
4903
5296
|
}
|
|
4904
|
-
// src/
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
persistent: options.persistent ?? true
|
|
4916
|
-
}, listener);
|
|
4917
|
-
watcher.on("error", (error) => {
|
|
4918
|
-
close(name);
|
|
4919
|
-
console.warn(`[verbaly] stopped watching ${name || "the project"}:`, error);
|
|
4920
|
-
});
|
|
4921
|
-
watchers.set(name, watcher);
|
|
4922
|
-
};
|
|
4923
|
-
if (options.native ?? NATIVE_TREE) open("", true, (_event, file) => {
|
|
4924
|
-
if (file) onFile(file);
|
|
5297
|
+
// src/cli/commands/render.ts
|
|
5298
|
+
async function renderCommand(cfg, values) {
|
|
5299
|
+
const result = await renderSite(cfg, {
|
|
5300
|
+
site: values.site,
|
|
5301
|
+
locales: csv(values.locales),
|
|
5302
|
+
attribute: values.attribute,
|
|
5303
|
+
base: values.base,
|
|
5304
|
+
baseUrl: values["base-url"],
|
|
5305
|
+
sitemap: values.sitemap,
|
|
5306
|
+
redirect: values.redirect,
|
|
5307
|
+
clean: values.clean
|
|
4925
5308
|
});
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
5309
|
+
console.log(`[verbaly] ${counted(result.files, "page")} × ${counted(result.locales.length, "locale")} (${result.locales.join(", ")})`);
|
|
5310
|
+
for (const line of formatRenderWarnings(result, cfg.sourceLocale)) console.warn(line);
|
|
5311
|
+
}
|
|
5312
|
+
// src/cli/commands/review.ts
|
|
5313
|
+
async function reviewCommand(cfg, values, positionals) {
|
|
5314
|
+
const registry = await extractProject(cfg);
|
|
5315
|
+
const catalogs = loadCatalogs(cfg);
|
|
5316
|
+
const shipped = shippedCatalogs(cfg, catalogs, registry);
|
|
5317
|
+
const state = loadState(cfg);
|
|
5318
|
+
const only = new Set(positionals.slice(1));
|
|
5319
|
+
const wanted = ({ locale, key }) => (!values.locale || locale === values.locale) && (only.size === 0 || only.has(key));
|
|
5320
|
+
const drafts = Object.entries(effectiveDrafts(state.drafts, catalogs)).flatMap(([locale, keys]) => keys.map((key) => ({
|
|
5321
|
+
locale,
|
|
5322
|
+
key
|
|
5323
|
+
}))).filter(wanted);
|
|
5324
|
+
const outdated = outdatedTranslations(cfg, shipped, state.fingerprints).filter(wanted);
|
|
5325
|
+
if (drafts.length === 0 && outdated.length === 0) {
|
|
5326
|
+
console.log("[verbaly] nothing awaiting review ✓");
|
|
5327
|
+
return;
|
|
4945
5328
|
}
|
|
4946
|
-
|
|
4947
|
-
for (const
|
|
5329
|
+
if (values.approve) {
|
|
5330
|
+
for (const [locale, keys] of byLocale(drafts)) {
|
|
5331
|
+
clearDrafts(state.drafts, locale, keys);
|
|
5332
|
+
console.log(` ${locale}: ${keys.length} approved`);
|
|
5333
|
+
}
|
|
5334
|
+
acceptOutdated(cfg, shipped, state.fingerprints, outdated);
|
|
5335
|
+
for (const [locale, keys] of byLocale(outdated)) console.log(` ${locale}: ${keys.length} kept for the new source text`);
|
|
5336
|
+
const lockBefore = stateFile(cfg);
|
|
5337
|
+
saveState(cfg, state);
|
|
5338
|
+
sayLockNews(cfg, lockBefore);
|
|
5339
|
+
const reviewed = new Set([...drafts, ...outdated].map(({ locale, key }) => `${locale}:${key}`));
|
|
5340
|
+
console.log(`[verbaly] ${counted(reviewed.size, "translation")} marked reviewed ✓`);
|
|
5341
|
+
return;
|
|
5342
|
+
}
|
|
5343
|
+
const source = shipped[cfg.sourceLocale] ?? {};
|
|
5344
|
+
const show = (locale, keys) => {
|
|
5345
|
+
console.log(` ${locale}:`);
|
|
5346
|
+
for (const key of keys) {
|
|
5347
|
+
const translated = catalogs[locale]?.[key] ?? "";
|
|
5348
|
+
console.log(` ${key}: "${truncate(source[key] ?? "", 60)}" → "${truncate(translated, 60)}"`);
|
|
5349
|
+
}
|
|
4948
5350
|
};
|
|
5351
|
+
if (drafts.length > 0) {
|
|
5352
|
+
console.log(`[verbaly] ${counted(drafts.length, "machine translation")} awaiting review (--approve to accept)`);
|
|
5353
|
+
for (const [locale, keys] of byLocale(drafts)) show(locale, keys);
|
|
5354
|
+
}
|
|
5355
|
+
if (outdated.length > 0) {
|
|
5356
|
+
console.log(`[verbaly] ${counted(outdated.length, "translation")} written for an older source text (update them, or --approve keeps them)`);
|
|
5357
|
+
for (const [locale, keys] of byLocale(outdated)) show(locale, keys);
|
|
5358
|
+
}
|
|
4949
5359
|
}
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
5360
|
+
// src/cli/commands/status.ts
|
|
5361
|
+
async function statusCommand(cfg, values) {
|
|
5362
|
+
const registry = await extractProject(cfg);
|
|
5363
|
+
const { state, problem } = readState(cfg);
|
|
5364
|
+
if (problem) console.warn(`[verbaly] ${problem}, so drafts and outdated translations are not counted`);
|
|
5365
|
+
const result = status(cfg, loadCatalogs(cfg), registry, state.drafts, state.fingerprints);
|
|
5366
|
+
console.log(values.json ? JSON.stringify(result) : formatStatusResult(result));
|
|
5367
|
+
}
|
|
5368
|
+
// src/cli/commands/translate.ts
|
|
5369
|
+
async function translateCommand(cfg, values) {
|
|
5370
|
+
if (!values["dry-run"]) loadState(cfg);
|
|
5371
|
+
const registry = await extractProject(cfg);
|
|
5372
|
+
const catalogs = shippedCatalogs(cfg, loadCatalogs(cfg), registry, { newKeys: false });
|
|
5373
|
+
const result = await translateCatalogs(cfg, catalogs, await resolveProvider(cfg, values.model), {
|
|
5374
|
+
locales: csv(values.locales),
|
|
5375
|
+
batchSize: cfg.translate.batchSize,
|
|
5376
|
+
concurrency: cfg.translate.concurrency,
|
|
5377
|
+
retries: cfg.translate.retries,
|
|
5378
|
+
dryRun: values["dry-run"],
|
|
5379
|
+
origins: values["dry-run"] ? void 0 : await collectOrigins(cfg, registry),
|
|
5380
|
+
onProgress: values["dry-run"] ? void 0 : reportProgress
|
|
5381
|
+
});
|
|
5382
|
+
if (values["dry-run"]) {
|
|
5383
|
+
const entries = Object.entries(result.pending);
|
|
5384
|
+
if (entries.length === 0) {
|
|
5385
|
+
console.log("[verbaly] nothing to translate ✓");
|
|
4958
5386
|
return;
|
|
4959
5387
|
}
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
await run();
|
|
4963
|
-
} catch (error) {
|
|
4964
|
-
console.warn("[verbaly] watch run failed:", error);
|
|
4965
|
-
} finally {
|
|
4966
|
-
running = false;
|
|
4967
|
-
if (queued) {
|
|
4968
|
-
queued = false;
|
|
4969
|
-
schedule();
|
|
4970
|
-
}
|
|
4971
|
-
}
|
|
5388
|
+
for (const [locale, keys] of entries) console.log(` ${locale}: ${keys.length} missing: ${keys.join(", ")}`);
|
|
5389
|
+
return;
|
|
4972
5390
|
}
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
5391
|
+
const source = catalogs[cfg.sourceLocale] ?? {};
|
|
5392
|
+
const writes = [];
|
|
5393
|
+
for (const [locale, keys] of Object.entries(result.translated)) {
|
|
5394
|
+
const catalog = catalogs[locale] ?? {};
|
|
5395
|
+
const written = mergeTranslations(cfg, locale, catalog, keys);
|
|
5396
|
+
writes.push({
|
|
5397
|
+
locale,
|
|
5398
|
+
draft: true,
|
|
5399
|
+
entries: written.map((key) => ({
|
|
5400
|
+
key,
|
|
5401
|
+
text: catalog[key]
|
|
5402
|
+
}))
|
|
5403
|
+
});
|
|
5404
|
+
console.log(` ${locale}: +${written.length} translated (draft)`);
|
|
5405
|
+
const kept = keys.length - written.length;
|
|
5406
|
+
if (kept > 0) console.log(` ${locale}: ${counted(kept, "message")} kept as written while this ran`);
|
|
5407
|
+
}
|
|
5408
|
+
const lockBefore = stateFile(cfg);
|
|
5409
|
+
if (writes.length > 0) recordTranslations(cfg, source, writes);
|
|
5410
|
+
sayLockNews(cfg, lockBefore);
|
|
5411
|
+
for (const [locale, keys] of Object.entries(result.invalid)) console.warn(` ${locale}: ${keys.length} rejected (params/tags not preserved): ${keys.join(", ")}`);
|
|
5412
|
+
for (const line of formatTranslateFailures(result.failed)) console.error(line);
|
|
5413
|
+
if (result.failed.length > 0) process.exitCode = 1;
|
|
5414
|
+
if (Object.keys(result.translated).length === 0 && Object.keys(result.invalid).length === 0 && result.failed.length === 0) console.log("[verbaly] nothing to translate ✓");
|
|
5415
|
+
}
|
|
5416
|
+
function reportProgress(progress) {
|
|
5417
|
+
const head = ` ${progress.locale} ${progress.batch}/${progress.batches}`;
|
|
5418
|
+
if (progress.error) console.warn(`${head}: failed (${progress.error}), continuing`);
|
|
5419
|
+
else console.log(`${head}: ${counted(progress.keys, "message")}`);
|
|
5420
|
+
}
|
|
5421
|
+
// src/cli/commands/typegen.ts
|
|
5422
|
+
async function typegenCommand(cfg) {
|
|
5423
|
+
const registry = await extractProject(cfg);
|
|
5424
|
+
const source = shippedCatalogs(cfg, loadCatalogs(cfg), registry)[cfg.sourceLocale] ?? {};
|
|
5425
|
+
const written = writeDts(cfg, source);
|
|
5426
|
+
if (!written) {
|
|
5427
|
+
console.log("[verbaly] no types written: dts is false in your verbaly config");
|
|
5428
|
+
return;
|
|
4976
5429
|
}
|
|
4977
|
-
const
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
if (file.includes("node_modules/") || file.endsWith(".d.ts")) return;
|
|
4981
|
-
if (catalogDir && file.startsWith(`${catalogDir}/`)) return;
|
|
4982
|
-
if (SOURCE_FILE_RE.test(file)) schedule();
|
|
4983
|
-
});
|
|
4984
|
-
return () => {
|
|
4985
|
-
clearTimeout(timer);
|
|
4986
|
-
close();
|
|
4987
|
-
};
|
|
5430
|
+
const where = relative(cfg.root, written.file).replaceAll("\\", "/");
|
|
5431
|
+
const how = written.changed ? "written to" : "up to date in";
|
|
5432
|
+
console.log(`[verbaly] types ${how} ${where} (${counted(Object.keys(source).length, "message")})`);
|
|
4988
5433
|
}
|
|
4989
|
-
// src/wrap.ts
|
|
5434
|
+
// src/scan/wrap.ts
|
|
4990
5435
|
const WRAP_ATTRS = /* @__PURE__ */ new Set([
|
|
4991
5436
|
"title",
|
|
4992
5437
|
"alt",
|
|
@@ -5261,7 +5706,38 @@ function trailingWs(text) {
|
|
|
5261
5706
|
function line(node) {
|
|
5262
5707
|
return node.loc?.start?.line ?? 1;
|
|
5263
5708
|
}
|
|
5264
|
-
// src/
|
|
5709
|
+
// src/cli/commands/wrap.ts
|
|
5710
|
+
async function wrapCommand(cfg, values) {
|
|
5711
|
+
const result = await wrapProject(cfg, { write: values.write });
|
|
5712
|
+
if (result.wrapped.length === 0 && result.skipped.length === 0) {
|
|
5713
|
+
console.log(`[verbaly] nothing to wrap (${counted(result.files, "file")} scanned) ✓`);
|
|
5714
|
+
return;
|
|
5715
|
+
}
|
|
5716
|
+
const blocked = new Set(result.blocked.map((entry) => entry.file));
|
|
5717
|
+
const done = result.changed.filter((file) => !blocked.has(file));
|
|
5718
|
+
const texts = result.wrapped.filter((entry) => !blocked.has(entry.file));
|
|
5719
|
+
const verb = values.write ? "wrapped" : "would wrap";
|
|
5720
|
+
const note = values.write ? "" : " (report only, use --write to apply)";
|
|
5721
|
+
const counts = values.write ? `${counted(texts.length, "text")} in ${counted(done.length, "file")}` : `${counted(result.wrapped.length, "text")} in ${counted(result.changed.length, "file")}`;
|
|
5722
|
+
console.log(`[verbaly] ${verb} ${counts}${note}`);
|
|
5723
|
+
for (const entry of values.write ? texts : result.wrapped) {
|
|
5724
|
+
const attr = entry.kind === "attribute" ? `${entry.attribute} → ` : "";
|
|
5725
|
+
console.log(` ${entry.file}:${entry.line} ${attr}"${entry.text}"`);
|
|
5726
|
+
}
|
|
5727
|
+
if (result.skipped.length > 0) {
|
|
5728
|
+
console.log(" needs a human:");
|
|
5729
|
+
for (const entry of result.skipped) console.log(` ${entry.file}:${entry.line} "${entry.text}" (${entry.reason})`);
|
|
5730
|
+
}
|
|
5731
|
+
if (result.blocked.length > 0) {
|
|
5732
|
+
console.log(` nothing written in ${counted(result.blocked.length, "file")} with no t in scope:`);
|
|
5733
|
+
for (const entry of result.blocked) {
|
|
5734
|
+
const how = entry.client ? "\"use client\", so const t = useT()" : "no \"use client\": check which side renders it before you pick the binding";
|
|
5735
|
+
console.log(` ${entry.file} ${counted(entry.texts, "text")}, ${how}`);
|
|
5736
|
+
}
|
|
5737
|
+
console.log(" next: add t there, run verbaly wrap --write again, then verbaly extract");
|
|
5738
|
+
} else if (values.write && done.length > 0) console.log(" next: run verbaly extract");
|
|
5739
|
+
}
|
|
5740
|
+
// src/cli/run.ts
|
|
5265
5741
|
const HELP = `verbaly · i18n compiler
|
|
5266
5742
|
|
|
5267
5743
|
Usage:
|
|
@@ -5313,45 +5789,23 @@ Options:
|
|
|
5313
5789
|
Config file: verbaly.config.{js,mjs,ts,mts,json} at root (flags win).
|
|
5314
5790
|
The claude provider needs @anthropic-ai/sdk installed and ANTHROPIC_API_KEY set.
|
|
5315
5791
|
`;
|
|
5792
|
+
const COMMANDS = {
|
|
5793
|
+
doctor: doctorCommand,
|
|
5794
|
+
extract: extractCommand,
|
|
5795
|
+
typegen: typegenCommand,
|
|
5796
|
+
migrate: migrateCommand,
|
|
5797
|
+
wrap: wrapCommand,
|
|
5798
|
+
status: statusCommand,
|
|
5799
|
+
check: checkCommand,
|
|
5800
|
+
translate: translateCommand,
|
|
5801
|
+
review: reviewCommand,
|
|
5802
|
+
export: exportCommand,
|
|
5803
|
+
import: importCommand,
|
|
5804
|
+
render: renderCommand,
|
|
5805
|
+
pseudo: pseudoCommand
|
|
5806
|
+
};
|
|
5316
5807
|
async function runCli(args = process.argv.slice(2)) {
|
|
5317
|
-
const { positionals, values } =
|
|
5318
|
-
args,
|
|
5319
|
-
allowPositionals: true,
|
|
5320
|
-
options: {
|
|
5321
|
-
root: { type: "string" },
|
|
5322
|
-
dir: { type: "string" },
|
|
5323
|
-
source: { type: "string" },
|
|
5324
|
-
locales: { type: "string" },
|
|
5325
|
-
prune: { type: "boolean" },
|
|
5326
|
-
watch: { type: "boolean" },
|
|
5327
|
-
write: { type: "boolean" },
|
|
5328
|
-
json: { type: "boolean" },
|
|
5329
|
-
drafts: { type: "boolean" },
|
|
5330
|
-
outdated: { type: "boolean" },
|
|
5331
|
-
draft: { type: "boolean" },
|
|
5332
|
-
approve: { type: "boolean" },
|
|
5333
|
-
reporter: { type: "string" },
|
|
5334
|
-
model: { type: "string" },
|
|
5335
|
-
locale: { type: "string" },
|
|
5336
|
-
site: { type: "string" },
|
|
5337
|
-
attribute: { type: "string" },
|
|
5338
|
-
base: { type: "string" },
|
|
5339
|
-
"base-url": { type: "string" },
|
|
5340
|
-
redirect: { type: "boolean" },
|
|
5341
|
-
sitemap: { type: "boolean" },
|
|
5342
|
-
clean: { type: "boolean" },
|
|
5343
|
-
"dry-run": { type: "boolean" },
|
|
5344
|
-
plurals: { type: "boolean" },
|
|
5345
|
-
format: { type: "string" },
|
|
5346
|
-
out: { type: "string" },
|
|
5347
|
-
missing: { type: "boolean" },
|
|
5348
|
-
overwrite: { type: "boolean" },
|
|
5349
|
-
help: {
|
|
5350
|
-
type: "boolean",
|
|
5351
|
-
short: "h"
|
|
5352
|
-
}
|
|
5353
|
-
}
|
|
5354
|
-
});
|
|
5808
|
+
const { positionals, values } = parseCli(args);
|
|
5355
5809
|
const command = positionals[0];
|
|
5356
5810
|
if (values.help || !command) {
|
|
5357
5811
|
console.log(HELP);
|
|
@@ -5359,442 +5813,20 @@ async function runCli(args = process.argv.slice(2)) {
|
|
|
5359
5813
|
return;
|
|
5360
5814
|
}
|
|
5361
5815
|
if (rejectStrayFlags(command, values)) return;
|
|
5362
|
-
if (command === "init")
|
|
5363
|
-
const result = await init({
|
|
5364
|
-
root: values.root,
|
|
5365
|
-
dir: values.dir,
|
|
5366
|
-
sourceLocale: values.source,
|
|
5367
|
-
locales: csv(values.locales)
|
|
5368
|
-
});
|
|
5369
|
-
if (result.created.length) console.log(`[verbaly] created: ${result.created.join(", ")}`);
|
|
5370
|
-
if (result.skipped.length) console.log(` kept (already there): ${result.skipped.join(", ")}`);
|
|
5371
|
-
for (const { from, to } of result.renamed) console.log(` wrote ${to} for ${from}, since a locale tag takes a hyphen`);
|
|
5372
|
-
for (const locale of result.refused) console.warn(` left out "${locale}": it is not a locale tag, use one like es or pt-BR`);
|
|
5373
|
-
if (result.found) console.log(` catalogs: ${result.found}, kept where they already are`);
|
|
5374
|
-
if (result.host) console.log(` detected: ${result.host}`);
|
|
5375
|
-
console.log([" next steps:", ...result.next.map((step, i) => ` ${i + 1}. ${step}`)].join("\n"));
|
|
5376
|
-
return;
|
|
5377
|
-
}
|
|
5816
|
+
if (command === "init") return initCommand(values);
|
|
5378
5817
|
const cfg = await loadConfig(values.root ?? process.cwd(), {
|
|
5379
5818
|
dir: values.dir,
|
|
5380
5819
|
sourceLocale: values.source,
|
|
5381
5820
|
locales: csv(values.locales)
|
|
5382
5821
|
});
|
|
5383
|
-
if (command
|
|
5384
|
-
const result = await doctor(cfg);
|
|
5385
|
-
console.log(`[verbaly] doctor: ${counted(result.entries.length, "check")}`);
|
|
5386
|
-
for (const entry of result.entries) {
|
|
5387
|
-
const line = formatDoctorEntry(entry);
|
|
5388
|
-
if (entry.level === "error") console.error(line);
|
|
5389
|
-
else if (entry.level === "warn") console.warn(line);
|
|
5390
|
-
else console.log(line);
|
|
5391
|
-
}
|
|
5392
|
-
if (result.ok) console.log(`[verbaly] ${formatDoctorHealth(result)} ✓`);
|
|
5393
|
-
else {
|
|
5394
|
-
console.error("[verbaly] doctor found problems");
|
|
5395
|
-
process.exitCode = 1;
|
|
5396
|
-
}
|
|
5397
|
-
return;
|
|
5398
|
-
}
|
|
5399
|
-
if (command === "extract") {
|
|
5400
|
-
const dryRun = values["dry-run"];
|
|
5401
|
-
if (values.watch && (dryRun || values.prune)) {
|
|
5402
|
-
console.error("[verbaly] --watch runs alone: prune is a deliberate one-shot action and dry-run writes nothing");
|
|
5403
|
-
process.exitCode = 1;
|
|
5404
|
-
return;
|
|
5405
|
-
}
|
|
5406
|
-
const reporter = values.watch ? createDevReporter(cfg.root, (line) => console.warn(` ${line}`)) : void 0;
|
|
5407
|
-
async function runExtract() {
|
|
5408
|
-
const result = await syncProject(cfg, {
|
|
5409
|
-
prune: values.prune,
|
|
5410
|
-
dryRun
|
|
5411
|
-
});
|
|
5412
|
-
if (result.pruneBlocked) {
|
|
5413
|
-
const unread = result.registry.parseErrors().length;
|
|
5414
|
-
console.warn(` prune skipped: an unparsed file may read any key (${counted(unread, "file")} below), so it waits until every file parses`);
|
|
5415
|
-
}
|
|
5416
|
-
for (const [locale, keys] of Object.entries(result.pruned)) console.log(dryRun ? ` ${locale}: would prune ${keys.length}: ${keys.join(", ")}` : ` ${locale}: -${keys.length} pruned`);
|
|
5417
|
-
const origin = result.inCode === result.messages ? "" : ` (${result.inCode} in code)`;
|
|
5418
|
-
console.log(`[verbaly] ${counted(result.messages, "message")}${origin} · locales: ${cfg.locales.join(", ")}${dryRun ? " (dry run, nothing written)" : ""}`);
|
|
5419
|
-
for (const [locale, keys] of Object.entries(result.added)) console.log(` ${locale}: ${dryRun ? `would add ${keys.length}` : `+${keys.length}`}`);
|
|
5420
|
-
const warnings = result.findings.filter((finding) => {
|
|
5421
|
-
if (finding.kind !== "replaced" && finding.kind !== "lock") return true;
|
|
5422
|
-
console.log(` ${formatFinding(finding, cfg.root)}`);
|
|
5423
|
-
return false;
|
|
5424
|
-
});
|
|
5425
|
-
if (reporter) reporter.report("extract", warnings);
|
|
5426
|
-
else for (const finding of warnings) console.warn(` ${formatFinding(finding, cfg.root)}`);
|
|
5427
|
-
if (result.stateProblem) console.warn(` ${result.stateProblem}, so drafts and outdated translations were not updated`);
|
|
5428
|
-
}
|
|
5429
|
-
await runExtract();
|
|
5430
|
-
if (values.watch) {
|
|
5431
|
-
watchProject(cfg, runExtract);
|
|
5432
|
-
console.log("[verbaly] watching for source changes (ctrl+c to stop)");
|
|
5433
|
-
}
|
|
5434
|
-
return;
|
|
5435
|
-
}
|
|
5436
|
-
if (command === "typegen") {
|
|
5437
|
-
const registry = await extractProject(cfg);
|
|
5438
|
-
const source = shippedCatalogs(cfg, loadCatalogs(cfg), registry)[cfg.sourceLocale] ?? {};
|
|
5439
|
-
const written = writeDts(cfg, source);
|
|
5440
|
-
if (!written) {
|
|
5441
|
-
console.log("[verbaly] no types written: dts is false in your verbaly config");
|
|
5442
|
-
return;
|
|
5443
|
-
}
|
|
5444
|
-
const where = relative(cfg.root, written.file).replaceAll("\\", "/");
|
|
5445
|
-
const how = written.changed ? "written to" : "up to date in";
|
|
5446
|
-
console.log(`[verbaly] types ${how} ${where} (${counted(Object.keys(source).length, "message")})`);
|
|
5447
|
-
return;
|
|
5448
|
-
}
|
|
5449
|
-
if (command === "migrate") {
|
|
5450
|
-
const lockBefore = stateFile(cfg);
|
|
5451
|
-
const result = migrateCatalogs(cfg, {
|
|
5452
|
-
write: values.write,
|
|
5453
|
-
plurals: values.plurals
|
|
5454
|
-
});
|
|
5455
|
-
const from = result.detected.length ? result.detected.join(", ") : "no known i18n library";
|
|
5456
|
-
const changes = result.braces.length + result.plurals.length;
|
|
5457
|
-
const before = result.remembered.length ? `, ${counted(result.remembered.length, "language")} converted before` : "";
|
|
5458
|
-
if (changes === 0 && result.skipped.length === 0) {
|
|
5459
|
-
console.log(`[verbaly] catalogs need nothing (${from}${before}) ✓`);
|
|
5460
|
-
return;
|
|
5461
|
-
}
|
|
5462
|
-
const verb = values.write ? "ported" : "would port";
|
|
5463
|
-
const note = values.write ? "" : " (report only, use --write to apply)";
|
|
5464
|
-
console.log(`[verbaly] ${verb} ${counted(changes, "message")} from ${from}${before}${note}`);
|
|
5465
|
-
for (const entry of result.braces) console.log(` ${entry.locale} ${entry.key} ${entry.before} → ${entry.after}`);
|
|
5466
|
-
for (const entry of result.plurals) console.log(` ${entry.locale} ${entry.key} ${entry.from.join(" + ")} → ${entry.after}`);
|
|
5467
|
-
if (!values.plurals && changes > 0) console.log(" --plurals also merges _one/_other into one message with variants");
|
|
5468
|
-
if (result.skipped.length > 0) {
|
|
5469
|
-
console.log(" needs a human:");
|
|
5470
|
-
for (const entry of result.skipped) console.log(` ${entry.locale} ${entry.key} ${entry.reason}`);
|
|
5471
|
-
}
|
|
5472
|
-
if (values.write && result.braces.length > 0) console.log(` ${STATE_FILE} remembers the converted languages, so a later run never reads them as i18next again`);
|
|
5473
|
-
sayLockNews(cfg, lockBefore);
|
|
5474
|
-
if (values.write) console.log(" next: run verbaly check");
|
|
5475
|
-
return;
|
|
5476
|
-
}
|
|
5477
|
-
if (command === "wrap") {
|
|
5478
|
-
const result = await wrapProject(cfg, { write: values.write });
|
|
5479
|
-
if (result.wrapped.length === 0 && result.skipped.length === 0) {
|
|
5480
|
-
console.log(`[verbaly] nothing to wrap (${counted(result.files, "file")} scanned) ✓`);
|
|
5481
|
-
return;
|
|
5482
|
-
}
|
|
5483
|
-
const blocked = new Set(result.blocked.map((entry) => entry.file));
|
|
5484
|
-
const done = result.changed.filter((file) => !blocked.has(file));
|
|
5485
|
-
const texts = result.wrapped.filter((entry) => !blocked.has(entry.file));
|
|
5486
|
-
const verb = values.write ? "wrapped" : "would wrap";
|
|
5487
|
-
const note = values.write ? "" : " (report only, use --write to apply)";
|
|
5488
|
-
const counts = values.write ? `${counted(texts.length, "text")} in ${counted(done.length, "file")}` : `${counted(result.wrapped.length, "text")} in ${counted(result.changed.length, "file")}`;
|
|
5489
|
-
console.log(`[verbaly] ${verb} ${counts}${note}`);
|
|
5490
|
-
for (const entry of values.write ? texts : result.wrapped) {
|
|
5491
|
-
const attr = entry.kind === "attribute" ? `${entry.attribute} → ` : "";
|
|
5492
|
-
console.log(` ${entry.file}:${entry.line} ${attr}"${entry.text}"`);
|
|
5493
|
-
}
|
|
5494
|
-
if (result.skipped.length > 0) {
|
|
5495
|
-
console.log(" needs a human:");
|
|
5496
|
-
for (const entry of result.skipped) console.log(` ${entry.file}:${entry.line} "${entry.text}" (${entry.reason})`);
|
|
5497
|
-
}
|
|
5498
|
-
if (result.blocked.length > 0) {
|
|
5499
|
-
console.log(` nothing written in ${counted(result.blocked.length, "file")} with no t in scope:`);
|
|
5500
|
-
for (const entry of result.blocked) {
|
|
5501
|
-
const how = entry.client ? "\"use client\", so const t = useT()" : "no \"use client\": check which side renders it before you pick the binding";
|
|
5502
|
-
console.log(` ${entry.file} ${counted(entry.texts, "text")}, ${how}`);
|
|
5503
|
-
}
|
|
5504
|
-
console.log(" next: add t there, run verbaly wrap --write again, then verbaly extract");
|
|
5505
|
-
} else if (values.write && done.length > 0) console.log(" next: run verbaly extract");
|
|
5506
|
-
return;
|
|
5507
|
-
}
|
|
5508
|
-
if (command === "status") {
|
|
5509
|
-
const registry = await extractProject(cfg);
|
|
5510
|
-
const { state, problem } = readState(cfg);
|
|
5511
|
-
if (problem) console.warn(`[verbaly] ${problem}, so drafts and outdated translations are not counted`);
|
|
5512
|
-
const result = status(cfg, loadCatalogs(cfg), registry, state.drafts, state.fingerprints);
|
|
5513
|
-
console.log(values.json ? JSON.stringify(result) : formatStatusResult(result));
|
|
5514
|
-
return;
|
|
5515
|
-
}
|
|
5516
|
-
if (command === "check") {
|
|
5517
|
-
const reporter = values.reporter ?? "text";
|
|
5518
|
-
if (reporter !== "text" && reporter !== "github") {
|
|
5519
|
-
console.error(`[verbaly] unknown reporter "${values.reporter}", use text or github`);
|
|
5520
|
-
process.exitCode = 1;
|
|
5521
|
-
return;
|
|
5522
|
-
}
|
|
5523
|
-
const registry = await extractProject(cfg);
|
|
5524
|
-
const catalogs = loadCatalogs(cfg);
|
|
5525
|
-
const state = checkState(cfg, values.drafts === true || values.outdated === true);
|
|
5526
|
-
const result = check(cfg, catalogs, registry, state.fingerprints);
|
|
5527
|
-
const unreviewed = values.drafts ? effectiveDrafts(state.drafts, catalogs) : {};
|
|
5528
|
-
const outdated = values.outdated ? result.outdated : [];
|
|
5529
|
-
const gated = { outdatedFails: values.outdated === true };
|
|
5530
|
-
if (reporter === "github") for (const line of githubCheckAnnotations(result, registry, cfg, gated)) console.error(line);
|
|
5531
|
-
else {
|
|
5532
|
-
const warnings = formatCheckWarnings(result, cfg.root, gated);
|
|
5533
|
-
if (warnings) console.warn(`[verbaly] warnings (the gate still passes)\n${warnings}`);
|
|
5534
|
-
}
|
|
5535
|
-
const awaiting = [...Object.entries(unreviewed).map(([locale, keys]) => ` [${locale}] ${keys.length} unreviewed: ${keys.join(", ")}`), ...byLocale(outdated).map(([locale, keys]) => ` [${locale}] ${keys.length} outdated: ${keys.join(", ")}`)];
|
|
5536
|
-
if (result.ok && awaiting.length === 0) {
|
|
5537
|
-
console.log("[verbaly] all translations complete ✓");
|
|
5538
|
-
return;
|
|
5539
|
-
}
|
|
5540
|
-
if (!result.ok) {
|
|
5541
|
-
const brokenCount = result.broken.filter((entry) => entry.severity === "error").length;
|
|
5542
|
-
const report = reporter === "github" ? `[verbaly] check failed: ${result.missing.length} missing, ${result.unknown.length} unknown, ${brokenCount} broken, ${counted(result.collisions.length, "collision")}` : `[verbaly] check failed\n${formatCheckResult(result, cfg.root)}`;
|
|
5543
|
-
console.error(`${report}\n${checkNextSteps(result)}`);
|
|
5544
|
-
}
|
|
5545
|
-
if (awaiting.length > 0) {
|
|
5546
|
-
for (const line of awaiting) console.error(line);
|
|
5547
|
-
console.error("[verbaly] check failed: translations awaiting review (run verbaly review, then --approve what holds)");
|
|
5548
|
-
}
|
|
5549
|
-
process.exitCode = 1;
|
|
5550
|
-
return;
|
|
5551
|
-
}
|
|
5552
|
-
if (command === "translate") {
|
|
5553
|
-
if (!values["dry-run"]) loadState(cfg);
|
|
5554
|
-
const registry = await extractProject(cfg);
|
|
5555
|
-
const catalogs = shippedCatalogs(cfg, loadCatalogs(cfg), registry, { newKeys: false });
|
|
5556
|
-
const result = await translateCatalogs(cfg, catalogs, await resolveProvider(cfg, values.model), {
|
|
5557
|
-
locales: csv(values.locales),
|
|
5558
|
-
batchSize: cfg.translate.batchSize,
|
|
5559
|
-
concurrency: cfg.translate.concurrency,
|
|
5560
|
-
retries: cfg.translate.retries,
|
|
5561
|
-
dryRun: values["dry-run"],
|
|
5562
|
-
origins: values["dry-run"] ? void 0 : await collectOrigins(cfg, registry),
|
|
5563
|
-
onProgress: values["dry-run"] ? void 0 : reportProgress
|
|
5564
|
-
});
|
|
5565
|
-
if (values["dry-run"]) {
|
|
5566
|
-
const entries = Object.entries(result.pending);
|
|
5567
|
-
if (entries.length === 0) {
|
|
5568
|
-
console.log("[verbaly] nothing to translate ✓");
|
|
5569
|
-
return;
|
|
5570
|
-
}
|
|
5571
|
-
for (const [locale, keys] of entries) console.log(` ${locale}: ${keys.length} missing: ${keys.join(", ")}`);
|
|
5572
|
-
return;
|
|
5573
|
-
}
|
|
5574
|
-
const source = catalogs[cfg.sourceLocale] ?? {};
|
|
5575
|
-
const writes = [];
|
|
5576
|
-
for (const [locale, keys] of Object.entries(result.translated)) {
|
|
5577
|
-
const catalog = catalogs[locale] ?? {};
|
|
5578
|
-
const written = mergeTranslations(cfg, locale, catalog, keys);
|
|
5579
|
-
writes.push({
|
|
5580
|
-
locale,
|
|
5581
|
-
draft: true,
|
|
5582
|
-
entries: written.map((key) => ({
|
|
5583
|
-
key,
|
|
5584
|
-
text: catalog[key]
|
|
5585
|
-
}))
|
|
5586
|
-
});
|
|
5587
|
-
console.log(` ${locale}: +${written.length} translated (draft)`);
|
|
5588
|
-
const kept = keys.length - written.length;
|
|
5589
|
-
if (kept > 0) console.log(` ${locale}: ${counted(kept, "message")} kept as written while this ran`);
|
|
5590
|
-
}
|
|
5591
|
-
const lockBefore = stateFile(cfg);
|
|
5592
|
-
if (writes.length > 0) recordTranslations(cfg, source, writes);
|
|
5593
|
-
sayLockNews(cfg, lockBefore);
|
|
5594
|
-
for (const [locale, keys] of Object.entries(result.invalid)) console.warn(` ${locale}: ${keys.length} rejected (params/tags not preserved): ${keys.join(", ")}`);
|
|
5595
|
-
for (const line of formatTranslateFailures(result.failed)) console.error(line);
|
|
5596
|
-
if (result.failed.length > 0) process.exitCode = 1;
|
|
5597
|
-
if (Object.keys(result.translated).length === 0 && Object.keys(result.invalid).length === 0 && result.failed.length === 0) console.log("[verbaly] nothing to translate ✓");
|
|
5598
|
-
return;
|
|
5599
|
-
}
|
|
5600
|
-
if (command === "review") {
|
|
5601
|
-
const registry = await extractProject(cfg);
|
|
5602
|
-
const catalogs = loadCatalogs(cfg);
|
|
5603
|
-
const shipped = shippedCatalogs(cfg, catalogs, registry);
|
|
5604
|
-
const state = loadState(cfg);
|
|
5605
|
-
const only = new Set(positionals.slice(1));
|
|
5606
|
-
const wanted = ({ locale, key }) => (!values.locale || locale === values.locale) && (only.size === 0 || only.has(key));
|
|
5607
|
-
const drafts = Object.entries(effectiveDrafts(state.drafts, catalogs)).flatMap(([locale, keys]) => keys.map((key) => ({
|
|
5608
|
-
locale,
|
|
5609
|
-
key
|
|
5610
|
-
}))).filter(wanted);
|
|
5611
|
-
const outdated = outdatedTranslations(cfg, shipped, state.fingerprints).filter(wanted);
|
|
5612
|
-
if (drafts.length === 0 && outdated.length === 0) {
|
|
5613
|
-
console.log("[verbaly] nothing awaiting review ✓");
|
|
5614
|
-
return;
|
|
5615
|
-
}
|
|
5616
|
-
if (values.approve) {
|
|
5617
|
-
for (const [locale, keys] of byLocale(drafts)) {
|
|
5618
|
-
clearDrafts(state.drafts, locale, keys);
|
|
5619
|
-
console.log(` ${locale}: ${keys.length} approved`);
|
|
5620
|
-
}
|
|
5621
|
-
acceptOutdated(cfg, shipped, state.fingerprints, outdated);
|
|
5622
|
-
for (const [locale, keys] of byLocale(outdated)) console.log(` ${locale}: ${keys.length} kept for the new source text`);
|
|
5623
|
-
const lockBefore = stateFile(cfg);
|
|
5624
|
-
saveState(cfg, state);
|
|
5625
|
-
sayLockNews(cfg, lockBefore);
|
|
5626
|
-
const reviewed = new Set([...drafts, ...outdated].map(({ locale, key }) => `${locale}:${key}`));
|
|
5627
|
-
console.log(`[verbaly] ${counted(reviewed.size, "translation")} marked reviewed ✓`);
|
|
5628
|
-
return;
|
|
5629
|
-
}
|
|
5630
|
-
const source = shipped[cfg.sourceLocale] ?? {};
|
|
5631
|
-
const show = (locale, keys) => {
|
|
5632
|
-
console.log(` ${locale}:`);
|
|
5633
|
-
for (const key of keys) {
|
|
5634
|
-
const translated = catalogs[locale]?.[key] ?? "";
|
|
5635
|
-
console.log(` ${key}: "${truncate(source[key] ?? "", 60)}" → "${truncate(translated, 60)}"`);
|
|
5636
|
-
}
|
|
5637
|
-
};
|
|
5638
|
-
if (drafts.length > 0) {
|
|
5639
|
-
console.log(`[verbaly] ${counted(drafts.length, "machine translation")} awaiting review (--approve to accept)`);
|
|
5640
|
-
for (const [locale, keys] of byLocale(drafts)) show(locale, keys);
|
|
5641
|
-
}
|
|
5642
|
-
if (outdated.length > 0) {
|
|
5643
|
-
console.log(`[verbaly] ${counted(outdated.length, "translation")} written for an older source text (update them, or --approve keeps them)`);
|
|
5644
|
-
for (const [locale, keys] of byLocale(outdated)) show(locale, keys);
|
|
5645
|
-
}
|
|
5646
|
-
return;
|
|
5647
|
-
}
|
|
5648
|
-
if (command === "export") {
|
|
5649
|
-
const format = values.format ?? "xliff";
|
|
5650
|
-
if (![
|
|
5651
|
-
"xliff",
|
|
5652
|
-
"csv",
|
|
5653
|
-
"po",
|
|
5654
|
-
"android-xml",
|
|
5655
|
-
"ios-strings"
|
|
5656
|
-
].includes(format)) {
|
|
5657
|
-
console.error(`[verbaly] unknown format "${values.format}", use xliff, csv, po, android-xml or ios-strings`);
|
|
5658
|
-
process.exitCode = 1;
|
|
5659
|
-
return;
|
|
5660
|
-
}
|
|
5661
|
-
if (values.missing && isMobileFormat(format)) {
|
|
5662
|
-
console.error(`[verbaly] --missing is for translator formats (xliff, csv): ${format} already skips untranslated keys so the app falls back to the source locale`);
|
|
5663
|
-
process.exitCode = 1;
|
|
5664
|
-
return;
|
|
5665
|
-
}
|
|
5666
|
-
const registry = await extractProject(cfg);
|
|
5667
|
-
const result = exportCatalogs(cfg, shippedCatalogs(cfg, loadCatalogs(cfg), registry, { newKeys: false }), {
|
|
5668
|
-
locales: csv(values.locales),
|
|
5669
|
-
format,
|
|
5670
|
-
out: values.out,
|
|
5671
|
-
missing: values.missing,
|
|
5672
|
-
origins: isMobileFormat(format) ? void 0 : await collectOrigins(cfg, registry)
|
|
5673
|
-
});
|
|
5674
|
-
if (result.files.length === 0) {
|
|
5675
|
-
console.log("[verbaly] no target locales to export (add locales to your config)");
|
|
5676
|
-
return;
|
|
5677
|
-
}
|
|
5678
|
-
const note = isMobileFormat(result.format) ? "untranslated skipped" : "untranslated";
|
|
5679
|
-
console.log(`[verbaly] exported ${counted(result.files.length, "locale")} (${result.format}) → ${result.dir}`);
|
|
5680
|
-
for (const file of result.files) console.log(` ${file.locale}: ${counted(file.total, "message")} (${file.untranslated} ${note}) → ${file.path}`);
|
|
5681
|
-
return;
|
|
5682
|
-
}
|
|
5683
|
-
if (command === "import") {
|
|
5684
|
-
const files = positionals.slice(1);
|
|
5685
|
-
if (files.length === 0) {
|
|
5686
|
-
console.error("[verbaly] import needs at least one file: verbaly import verbaly-export/es.xlf");
|
|
5687
|
-
process.exitCode = 1;
|
|
5688
|
-
return;
|
|
5689
|
-
}
|
|
5690
|
-
if (!values["dry-run"]) loadState(cfg);
|
|
5691
|
-
const registry = await extractProject(cfg);
|
|
5692
|
-
const catalogs = shippedCatalogs(cfg, loadCatalogs(cfg), registry, { newKeys: false });
|
|
5693
|
-
const result = importCatalogs(cfg, catalogs, files, {
|
|
5694
|
-
locale: values.locale,
|
|
5695
|
-
overwrite: values.overwrite,
|
|
5696
|
-
dryRun: values["dry-run"]
|
|
5697
|
-
});
|
|
5698
|
-
for (const { file, from, to } of result.mapped) console.log(` ${file}: "${from}" read as ${to}`);
|
|
5699
|
-
for (const { file, locale, reason } of result.unmatched) {
|
|
5700
|
-
if (reason === "undeclared") {
|
|
5701
|
-
console.warn(` ${file}: "${locale}" is not one of this project's locales (${cfg.locales.join(", ")}), so nothing was imported from it`);
|
|
5702
|
-
console.warn(` fix: add ${locale} to locales in your verbaly config, or pass --locale with one of them`);
|
|
5703
|
-
} else {
|
|
5704
|
-
console.warn(` ${file}: "${locale}" is not a locale tag, so nothing was imported from it`);
|
|
5705
|
-
console.warn(" fix: pass --locale with the tag it stands for, like pt-BR");
|
|
5706
|
-
}
|
|
5707
|
-
process.exitCode = 1;
|
|
5708
|
-
}
|
|
5709
|
-
const writes = [];
|
|
5710
|
-
for (const [locale, keys] of Object.entries(result.imported)) {
|
|
5711
|
-
if (!values["dry-run"]) {
|
|
5712
|
-
const catalog = catalogs[locale] ?? {};
|
|
5713
|
-
writeCatalog(cfg, locale, catalog);
|
|
5714
|
-
const seen = result.sources[locale] ?? {};
|
|
5715
|
-
const entries = keys.map((key) => ({
|
|
5716
|
-
key,
|
|
5717
|
-
text: catalog[key],
|
|
5718
|
-
source: seen[key]
|
|
5719
|
-
}));
|
|
5720
|
-
writes.push({
|
|
5721
|
-
locale,
|
|
5722
|
-
entries,
|
|
5723
|
-
draft: values.draft === true
|
|
5724
|
-
});
|
|
5725
|
-
}
|
|
5726
|
-
const verb = values["dry-run"] ? "would import" : "imported";
|
|
5727
|
-
console.log(` ${locale}: +${keys.length} ${verb}${values.draft ? " (draft)" : ""}`);
|
|
5728
|
-
}
|
|
5729
|
-
const lockBefore = stateFile(cfg);
|
|
5730
|
-
if (writes.length > 0) recordTranslations(cfg, catalogs[cfg.sourceLocale] ?? {}, writes);
|
|
5731
|
-
sayLockNews(cfg, lockBefore);
|
|
5732
|
-
for (const [locale, keys] of Object.entries(result.skipped)) console.log(` ${locale}: ${keys.length} already translated, kept (use --overwrite to replace)`);
|
|
5733
|
-
for (const [locale, keys] of Object.entries(result.rejected)) console.warn(` ${locale}: ${keys.length} rejected (params/tags not preserved): ${keys.join(", ")}`);
|
|
5734
|
-
for (const [locale, keys] of Object.entries(result.unknown)) console.warn(` ${locale}: ${counted(keys.length, "unknown key")} ignored (not in the source catalog): ${keys.join(", ")}`);
|
|
5735
|
-
if (Object.keys(result.imported).length === 0 && result.unmatched.length === 0) console.log("[verbaly] nothing to import ✓");
|
|
5736
|
-
return;
|
|
5737
|
-
}
|
|
5738
|
-
if (command === "render") {
|
|
5739
|
-
const result = await renderSite(cfg, {
|
|
5740
|
-
site: values.site,
|
|
5741
|
-
locales: csv(values.locales),
|
|
5742
|
-
attribute: values.attribute,
|
|
5743
|
-
base: values.base,
|
|
5744
|
-
baseUrl: values["base-url"],
|
|
5745
|
-
sitemap: values.sitemap,
|
|
5746
|
-
redirect: values.redirect,
|
|
5747
|
-
clean: values.clean
|
|
5748
|
-
});
|
|
5749
|
-
console.log(`[verbaly] ${counted(result.files, "page")} × ${counted(result.locales.length, "locale")} (${result.locales.join(", ")})`);
|
|
5750
|
-
for (const line of formatRenderWarnings(result, cfg.sourceLocale)) console.warn(line);
|
|
5751
|
-
return;
|
|
5752
|
-
}
|
|
5753
|
-
if (command === "pseudo") {
|
|
5754
|
-
const catalogs = shippedCatalogs(cfg, loadCatalogs(cfg), await extractProject(cfg), { newKeys: false });
|
|
5755
|
-
const locale = values.locale ?? "en-XA";
|
|
5756
|
-
const keys = pseudoCatalogs(cfg, catalogs, locale);
|
|
5757
|
-
writeCatalog(cfg, locale, catalogs[locale] ?? {});
|
|
5758
|
-
console.log(`[verbaly] ${counted(keys.length, "message")} pseudo-localized → ${locale}`);
|
|
5759
|
-
return;
|
|
5760
|
-
}
|
|
5822
|
+
if (Object.hasOwn(COMMANDS, command)) return COMMANDS[command](cfg, values, positionals);
|
|
5761
5823
|
console.error(`[verbaly] unknown command "${command}"\n${HELP}`);
|
|
5762
5824
|
process.exitCode = 1;
|
|
5763
5825
|
}
|
|
5764
|
-
function csv(value) {
|
|
5765
|
-
return value?.split(",").map((item) => item.trim()).filter(Boolean);
|
|
5766
|
-
}
|
|
5767
|
-
function reportProgress(progress) {
|
|
5768
|
-
const head = ` ${progress.locale} ${progress.batch}/${progress.batches}`;
|
|
5769
|
-
if (progress.error) console.warn(`${head}: failed (${progress.error}), continuing`);
|
|
5770
|
-
else console.log(`${head}: ${counted(progress.keys, "message")}`);
|
|
5771
|
-
}
|
|
5772
5826
|
function formatCliError(error) {
|
|
5773
5827
|
const message = error instanceof Error ? error.message : String(error);
|
|
5774
5828
|
return message.startsWith("[verbaly]") ? message : `[verbaly] ${message}`;
|
|
5775
5829
|
}
|
|
5776
|
-
function checkState(cfg, gating) {
|
|
5777
|
-
if (gating) return loadState(cfg);
|
|
5778
|
-
const { state, problem } = readState(cfg);
|
|
5779
|
-
if (problem) console.warn(`[verbaly] ${problem}, so outdated translations are not reported`);
|
|
5780
|
-
return state;
|
|
5781
|
-
}
|
|
5782
|
-
function sayLockNews(cfg, before) {
|
|
5783
|
-
const news = lockNews(cfg, before);
|
|
5784
|
-
if (news) console.log(` ${formatFinding({
|
|
5785
|
-
kind: "lock",
|
|
5786
|
-
...news
|
|
5787
|
-
}, cfg.root)}`);
|
|
5788
|
-
}
|
|
5789
|
-
function byLocale(entries) {
|
|
5790
|
-
const out = /* @__PURE__ */ new Map();
|
|
5791
|
-
for (const { locale, key } of entries) {
|
|
5792
|
-
const keys = out.get(locale);
|
|
5793
|
-
if (keys) keys.push(key);
|
|
5794
|
-
else out.set(locale, [key]);
|
|
5795
|
-
}
|
|
5796
|
-
return [...out];
|
|
5797
|
-
}
|
|
5798
5830
|
const COMMON_FLAGS = /* @__PURE__ */ new Set([
|
|
5799
5831
|
"root",
|
|
5800
5832
|
"dir",
|
|
@@ -5844,13 +5876,12 @@ const COMMAND_FLAGS = {
|
|
|
5844
5876
|
]
|
|
5845
5877
|
};
|
|
5846
5878
|
function rejectStrayFlags(command, values) {
|
|
5847
|
-
|
|
5848
|
-
|
|
5849
|
-
const allowed = /* @__PURE__ */ new Set([...COMMON_FLAGS, ...own]);
|
|
5879
|
+
if (!Object.hasOwn(COMMAND_FLAGS, command)) return false;
|
|
5880
|
+
const allowed = /* @__PURE__ */ new Set([...COMMON_FLAGS, ...COMMAND_FLAGS[command]]);
|
|
5850
5881
|
const stray = Object.keys(values).filter((k) => values[k] !== void 0 && !allowed.has(k));
|
|
5851
5882
|
if (stray.length === 0) return false;
|
|
5852
5883
|
for (const flag of stray) console.error(`[verbaly] --${flag} is not a "${command}" flag${flag === "locale" ? " (did you mean --locales?)" : ""}`);
|
|
5853
5884
|
process.exitCode = 1;
|
|
5854
5885
|
return true;
|
|
5855
5886
|
}
|
|
5856
|
-
export {
|
|
5887
|
+
export { validatePair as $, check as A, readState as B, isTransformTarget as C, transformSource as D, runBuildGate as E, clearDrafts as F, createDevReporter as G, saveState as H, effectiveDrafts as I, generateDts as J, formatCollision as K, loadState as L, formatCheckWarnings as M, syncProject as N, writeBuildTypes as O, STATE_FILE as P, validateMessage as Q, markDrafts as R, createSourceFilter as S, resolveVirtualId as T, updateState as U, recordTranslations as V, collisionEntries as W, generateRuntimeModule as X, generateLocaleModule as Y, writeDts as Z, status as _, isModuleNotFound as _t, renderSite as a, stableKey as at, RESOLVED_VIRTUAL_ID as b, targetLocales as bt, formatTranslateFailures as c, MessageRegistry as ct, translateCatalogs as d, loadCatalogs as dt, collectOrigins as et, writeDrafts as f, needsIcu as ft, formatStatusResult as g, writeCatalog as gt, formatDoctorHealth as h, readCatalog as ht, formatRenderWarnings as i, syncCatalogs as it, formatCheckResult as j, transformCode as k, mergeTranslations as l, clientCatalogs as lt, formatDoctorEntry as m, parseCatalog as mt, runCli as n, pruneCatalogs as nt, init as o, APP_ID as ot, doctor as p, needsRelative as pt, formatFinding as q, wrapProject as r, shippedCatalogs as rt, watchTree as s, LOCALE_IMPORT as st, formatCliError as t, extractProject as tt, resolveProvider as u, counted as ut, reportOutsideInclude as v, loadConfig as vt, loadVirtualModule as w, SOURCE_FILE_RE as x, LOCALE_MODULE_PREFIX as y, resolveConfig as yt, outdatedTranslations as z };
|