@verbaly/compiler 0.30.0 → 0.31.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 +40 -7
- package/dist/cli.js +0 -0
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +13 -3
- package/dist/index.js +147 -68
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -160,8 +160,10 @@ interface CheckResult {
|
|
|
160
160
|
unknown: UnknownEntry[];
|
|
161
161
|
broken: BrokenEntry[];
|
|
162
162
|
}
|
|
163
|
+
declare function gatePasses(result: Omit<CheckResult, 'ok'>): boolean;
|
|
163
164
|
declare function check(cfg: ResolvedConfig, catalogs: Catalogs, registry: MessageRegistry): CheckResult;
|
|
164
165
|
declare function formatCheckResult(result: CheckResult): string;
|
|
166
|
+
declare function checkNextSteps(result: CheckResult): string;
|
|
165
167
|
declare function formatCheckWarnings(result: CheckResult): string;
|
|
166
168
|
declare function githubCheckAnnotations(result: CheckResult, registry: MessageRegistry, root: string): string[];
|
|
167
169
|
//#endregion
|
|
@@ -283,11 +285,19 @@ interface InitOptions {
|
|
|
283
285
|
interface InitResult {
|
|
284
286
|
created: string[];
|
|
285
287
|
skipped: string[];
|
|
286
|
-
|
|
288
|
+
host: Host | undefined;
|
|
287
289
|
configFile: string;
|
|
288
290
|
next: string[];
|
|
289
291
|
}
|
|
290
|
-
|
|
292
|
+
type Host = 'nuxt' | 'next' | 'sveltekit' | 'astro' | 'vite' | 'webpack' | 'rspack' | 'rollup' | 'esbuild';
|
|
293
|
+
interface HostSetup {
|
|
294
|
+
name: Host;
|
|
295
|
+
pkg: string;
|
|
296
|
+
wire: string;
|
|
297
|
+
}
|
|
298
|
+
declare const WIRING_PACKAGES: string[];
|
|
299
|
+
declare function readDependencies(root: string): Record<string, string>;
|
|
300
|
+
declare function detectHost(root: string): HostSetup | undefined;
|
|
291
301
|
declare function init(options?: InitOptions): InitResult;
|
|
292
302
|
//#endregion
|
|
293
303
|
//#region src/key.d.ts
|
|
@@ -402,5 +412,5 @@ interface WrapCodeResult {
|
|
|
402
412
|
}
|
|
403
413
|
declare function wrapCode(code: string, file: string): WrapCodeResult;
|
|
404
414
|
//#endregion
|
|
405
|
-
export { type Alternate, type Analysis, type AnalyzeOptions, type BrokenEntry, type Catalog, type Catalogs, type CheckResult, type ClaudeProviderOptions, DRAFTS_FILE, type DoctorEntry, type DoctorResult, type Drafts, type ExchangeFormat, type ExportFormat, type ExportOptions, type ExportResult, type ExportedFile, type ImportOptions, type ImportResult, type InitOptions, type InitResult, type IssueSeverity, LOCALE_MODULE_PREFIX, type LocaleStatus, MessageRegistry, type MissingEntry, type MobileFormat, PLURAL_CATEGORIES, PSEUDO_LOCALE, type ParamType, type PluginOptions, RESOLVED_VIRTUAL_ID, type RenderConfig, type RenderHtmlOptions, type RenderHtmlResult, type RenderSiteOptions, type RenderSiteResult, type ResolvedConfig, type RuntimeModuleOptions, SFC_FILE_RE, SOURCE_FILE_RE, type StatusResult, type StructureIssue, type SyncResult, type TaggedMessage, type TaggedParam, type TransComponent, type TransformResult, type TranslateConfig, type TranslateOptions, type TranslateProvider, type TranslateRequest, type TranslateResult, type UnknownEntry, type UsedKey, VIRTUAL_ID, type VerbalyConfig, type WatchProjectOptions, type WrapCodeResult, type WrapEntry, type WrapOptions, type WrapResult, type WrapSkip, analyze, analyzeFile, analyzeSfc, catalogPath, check, claudeProvider, clearDrafts, collectOrigins, collectParams, createSourceFilter,
|
|
415
|
+
export { type Alternate, type Analysis, type AnalyzeOptions, type BrokenEntry, type Catalog, type Catalogs, type CheckResult, type ClaudeProviderOptions, DRAFTS_FILE, type DoctorEntry, type DoctorResult, type Drafts, type ExchangeFormat, type ExportFormat, type ExportOptions, type ExportResult, type ExportedFile, type Host, type HostSetup, type ImportOptions, type ImportResult, type InitOptions, type InitResult, type IssueSeverity, LOCALE_MODULE_PREFIX, type LocaleStatus, MessageRegistry, type MissingEntry, type MobileFormat, PLURAL_CATEGORIES, PSEUDO_LOCALE, type ParamType, type PluginOptions, RESOLVED_VIRTUAL_ID, type RenderConfig, type RenderHtmlOptions, type RenderHtmlResult, type RenderSiteOptions, type RenderSiteResult, type ResolvedConfig, type RuntimeModuleOptions, SFC_FILE_RE, SOURCE_FILE_RE, type StatusResult, type StructureIssue, type SyncResult, type TaggedMessage, type TaggedParam, type TransComponent, type TransformResult, type TranslateConfig, type TranslateOptions, type TranslateProvider, type TranslateRequest, type TranslateResult, type UnknownEntry, type UsedKey, VIRTUAL_ID, type VerbalyConfig, WIRING_PACKAGES, type WatchProjectOptions, type WrapCodeResult, type WrapEntry, type WrapOptions, type WrapResult, type WrapSkip, analyze, analyzeFile, analyzeSfc, catalogPath, check, checkNextSteps, claudeProvider, clearDrafts, collectOrigins, collectParams, createSourceFilter, detectHost, doctor, effectiveDrafts, exportCatalogs, extractProject, findConfigFile, formatCheckResult, formatCheckWarnings, formatStatusResult, gatePasses, generateDts, generateLocaleModule, generateRuntimeModule, githubCheckAnnotations, importCatalogs, init, isMobileFormat, isTransformTarget, loadCatalogs, loadConfig, loadConfigFile, loadDrafts, loadVirtualModule, markDrafts, parseExchangeFile, pruneCatalogs, pseudoCatalogs, pseudoLocalize, readCatalog, readDependencies, renderHtml, renderParamType, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, serializeCatalog, stableKey, status, structureMatches, syncCatalogs, targetLocales, transformCode, transformSource, translateCatalogs, validateMessage, validatePair, watchProject, wrapCode, wrapProject, writeCatalog, writeDts };
|
|
406
416
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -505,9 +505,14 @@ function collect(nodes, out) {
|
|
|
505
505
|
}
|
|
506
506
|
}
|
|
507
507
|
const TAG = /<(\/?)([a-zA-Z][\w-]*)(\/?)>/g;
|
|
508
|
-
function
|
|
508
|
+
function markupNames(message) {
|
|
509
|
+
const out = /* @__PURE__ */ new Set();
|
|
510
|
+
for (const match of message.matchAll(TAG)) if (match[1] || match[3]) out.add(match[2]);
|
|
511
|
+
return out;
|
|
512
|
+
}
|
|
513
|
+
function tagTokens(message, markup) {
|
|
509
514
|
const out = [];
|
|
510
|
-
for (const match of message.matchAll(TAG)) out.push(`${match[1]}${match[2]}${match[3]}`);
|
|
515
|
+
for (const match of message.matchAll(TAG)) if (markup.has(match[2])) out.push(`${match[1]}${match[2]}${match[3]}`);
|
|
511
516
|
return out.sort();
|
|
512
517
|
}
|
|
513
518
|
function surplus(a, b) {
|
|
@@ -555,8 +560,9 @@ function validatePair(source, translated) {
|
|
|
555
560
|
severity: "error",
|
|
556
561
|
message: `${list(newParams.map((name) => `{${name}}`))} ${newParams.length > 1 ? "are" : "is"} not in the source message, so ${newParams.length > 1 ? "they render" : "it renders"} as literal text`
|
|
557
562
|
});
|
|
558
|
-
const
|
|
559
|
-
const
|
|
563
|
+
const markup = /* @__PURE__ */ new Set([...markupNames(source), ...markupNames(translated)]);
|
|
564
|
+
const lostTags = tagReport(surplus(tagTokens(source, markup), tagTokens(translated, markup)));
|
|
565
|
+
const newTags = tagReport(surplus(tagTokens(translated, markup), tagTokens(source, markup)));
|
|
560
566
|
if (lostTags.length > 0) issues.push({
|
|
561
567
|
severity: "error",
|
|
562
568
|
message: `${list(lostTags)} ${lostTags.length > 1 ? "are" : "is"} missing from the translation`
|
|
@@ -602,7 +608,7 @@ const COUNT_PROBE = 200;
|
|
|
602
608
|
const reachable = /* @__PURE__ */ new Map();
|
|
603
609
|
function reachableCategories(locale, ordinal) {
|
|
604
610
|
const type = ordinal ? "ordinal" : "cardinal";
|
|
605
|
-
const cacheKey = `${locale}
|
|
611
|
+
const cacheKey = `${locale}\u0000${type}`;
|
|
606
612
|
const hit = reachable.get(cacheKey);
|
|
607
613
|
if (hit) return hit;
|
|
608
614
|
let out;
|
|
@@ -619,11 +625,16 @@ function reachableCategories(locale, ordinal) {
|
|
|
619
625
|
}
|
|
620
626
|
//#endregion
|
|
621
627
|
//#region src/check.ts
|
|
628
|
+
function gatePasses(result) {
|
|
629
|
+
return result.missing.length === 0 && result.unknown.length === 0 && !result.broken.some((entry) => entry.severity === "error");
|
|
630
|
+
}
|
|
622
631
|
function check(cfg, catalogs, registry) {
|
|
623
|
-
const source = catalogs[cfg.sourceLocale] ?? {};
|
|
624
632
|
const extracted = registry.messages();
|
|
633
|
+
const flat = {};
|
|
634
|
+
for (const locale of cfg.locales) flat[locale] = flatten(catalogs[locale] ?? {});
|
|
635
|
+
const source = flat[cfg.sourceLocale] ?? {};
|
|
625
636
|
const unknown = [];
|
|
626
|
-
for (const [key, files] of registry.usedKeys()) if (!(extracted.has(key) || cfg.locales.some((locale) =>
|
|
637
|
+
for (const [key, files] of registry.usedKeys()) if (!(extracted.has(key) || cfg.locales.some((locale) => flat[locale]?.[key] !== void 0))) unknown.push({
|
|
627
638
|
key,
|
|
628
639
|
files
|
|
629
640
|
});
|
|
@@ -636,7 +647,7 @@ function check(cfg, catalogs, registry) {
|
|
|
636
647
|
});
|
|
637
648
|
for (const locale of cfg.locales) {
|
|
638
649
|
if (locale === cfg.sourceLocale) continue;
|
|
639
|
-
for (const key of needed) if (!
|
|
650
|
+
for (const key of needed) if (!flat[locale]?.[key]) missing.push({
|
|
640
651
|
locale,
|
|
641
652
|
key,
|
|
642
653
|
source: source[key] ?? extracted.get(key)?.message
|
|
@@ -651,23 +662,24 @@ function check(cfg, catalogs, registry) {
|
|
|
651
662
|
issue: issue.message
|
|
652
663
|
});
|
|
653
664
|
};
|
|
654
|
-
const
|
|
655
|
-
for (const key of
|
|
656
|
-
|
|
657
|
-
if (text) sourceFlat[key] = text;
|
|
658
|
-
}
|
|
659
|
-
for (const [key, text] of Object.entries(sourceFlat)) add(cfg.sourceLocale, key, validateMessage(text, cfg.sourceLocale));
|
|
665
|
+
const sourceText = { ...source };
|
|
666
|
+
for (const [key, entry] of extracted) if (!sourceText[key]) sourceText[key] = entry.message;
|
|
667
|
+
for (const [key, text] of Object.entries(sourceText)) add(cfg.sourceLocale, key, validateMessage(text, cfg.sourceLocale));
|
|
660
668
|
for (const locale of cfg.locales) {
|
|
661
669
|
if (locale === cfg.sourceLocale) continue;
|
|
662
|
-
for (const [key, translated] of Object.entries(
|
|
670
|
+
for (const [key, translated] of Object.entries(flat[locale] ?? {})) {
|
|
663
671
|
if (!translated) continue;
|
|
664
672
|
add(locale, key, validateMessage(translated, locale));
|
|
665
|
-
const text =
|
|
673
|
+
const text = sourceText[key];
|
|
666
674
|
if (text) add(locale, key, validatePair(text, translated));
|
|
667
675
|
}
|
|
668
676
|
}
|
|
669
677
|
return {
|
|
670
|
-
ok:
|
|
678
|
+
ok: gatePasses({
|
|
679
|
+
missing,
|
|
680
|
+
unknown,
|
|
681
|
+
broken
|
|
682
|
+
}),
|
|
671
683
|
missing,
|
|
672
684
|
unknown,
|
|
673
685
|
broken
|
|
@@ -693,6 +705,13 @@ function formatCheckResult(result) {
|
|
|
693
705
|
}
|
|
694
706
|
return lines.join("\n");
|
|
695
707
|
}
|
|
708
|
+
function checkNextSteps(result) {
|
|
709
|
+
const steps = [];
|
|
710
|
+
if (result.missing.length > 0) steps.push("missing: run `npx verbaly extract` to scaffold the keys, then fill them (or run `npx verbaly translate`)");
|
|
711
|
+
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`");
|
|
712
|
+
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");
|
|
713
|
+
return steps.join("\n");
|
|
714
|
+
}
|
|
696
715
|
function formatCheckWarnings(result) {
|
|
697
716
|
return result.broken.filter((entry) => entry.severity === "warning").map((entry) => ` [${entry.locale}] ${entry.key}: ${entry.issue}`).join("\n");
|
|
698
717
|
}
|
|
@@ -1182,9 +1201,13 @@ function transformSource(code, id, registry) {
|
|
|
1182
1201
|
};
|
|
1183
1202
|
}
|
|
1184
1203
|
function runBuildGate(cfg, registry, failOnMissing) {
|
|
1185
|
-
|
|
1186
|
-
const result =
|
|
1187
|
-
|
|
1204
|
+
const found = check(cfg, loadCatalogs(cfg), registry);
|
|
1205
|
+
const result = failOnMissing === false ? {
|
|
1206
|
+
...found,
|
|
1207
|
+
missing: []
|
|
1208
|
+
} : found;
|
|
1209
|
+
if (gatePasses(result)) return;
|
|
1210
|
+
throw new Error(`[verbaly] build blocked\n${formatCheckResult(result)}\n${checkNextSteps(result)}`);
|
|
1188
1211
|
}
|
|
1189
1212
|
//#endregion
|
|
1190
1213
|
//#region src/registry.ts
|
|
@@ -1278,28 +1301,80 @@ function pruneCatalogs(cfg, catalogs, registry) {
|
|
|
1278
1301
|
}
|
|
1279
1302
|
//#endregion
|
|
1280
1303
|
//#region src/init.ts
|
|
1281
|
-
const
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1304
|
+
const HOSTS = [
|
|
1305
|
+
{
|
|
1306
|
+
name: "nuxt",
|
|
1307
|
+
dep: "nuxt",
|
|
1308
|
+
pkg: "@verbaly/nuxt",
|
|
1309
|
+
wire: "add '@verbaly/nuxt' to the modules in nuxt.config"
|
|
1310
|
+
},
|
|
1311
|
+
{
|
|
1312
|
+
name: "next",
|
|
1313
|
+
dep: "next",
|
|
1314
|
+
pkg: "@verbaly/next",
|
|
1315
|
+
wire: "wrap the export of next.config with withVerbaly"
|
|
1316
|
+
},
|
|
1317
|
+
{
|
|
1318
|
+
name: "sveltekit",
|
|
1319
|
+
dep: "@sveltejs/kit",
|
|
1320
|
+
pkg: "@verbaly/vite",
|
|
1321
|
+
wire: "add verbaly() to the plugins in vite.config (per-request locale: @verbaly/sveltekit)"
|
|
1322
|
+
},
|
|
1323
|
+
{
|
|
1324
|
+
name: "astro",
|
|
1325
|
+
dep: "astro",
|
|
1326
|
+
pkg: "@verbaly/astro",
|
|
1327
|
+
wire: "add verbaly() to the integrations in astro.config"
|
|
1328
|
+
},
|
|
1329
|
+
{
|
|
1330
|
+
name: "vite",
|
|
1331
|
+
dep: "vite",
|
|
1332
|
+
pkg: "@verbaly/vite",
|
|
1333
|
+
wire: "add verbaly() to the plugins in vite.config"
|
|
1334
|
+
},
|
|
1335
|
+
{
|
|
1336
|
+
name: "webpack",
|
|
1337
|
+
dep: "webpack",
|
|
1338
|
+
pkg: "@verbaly/unplugin",
|
|
1339
|
+
wire: "add the verbaly webpack plugin to your build config"
|
|
1340
|
+
},
|
|
1341
|
+
{
|
|
1342
|
+
name: "rspack",
|
|
1343
|
+
dep: "@rspack/core",
|
|
1344
|
+
pkg: "@verbaly/unplugin",
|
|
1345
|
+
wire: "add the verbaly rspack plugin to your build config"
|
|
1346
|
+
},
|
|
1347
|
+
{
|
|
1348
|
+
name: "rollup",
|
|
1349
|
+
dep: "rollup",
|
|
1350
|
+
pkg: "@verbaly/unplugin",
|
|
1351
|
+
wire: "add the verbaly rollup plugin to your build config"
|
|
1352
|
+
},
|
|
1353
|
+
{
|
|
1354
|
+
name: "esbuild",
|
|
1355
|
+
dep: "esbuild",
|
|
1356
|
+
pkg: "@verbaly/unplugin",
|
|
1357
|
+
wire: "add the verbaly esbuild plugin to your build config"
|
|
1358
|
+
}
|
|
1288
1359
|
];
|
|
1289
|
-
|
|
1360
|
+
const WIRING_PACKAGES = [...new Set(HOSTS.map((host) => host.pkg))];
|
|
1361
|
+
function readDependencies(root) {
|
|
1290
1362
|
const path = join(root, "package.json");
|
|
1291
|
-
if (!existsSync(path)) return
|
|
1363
|
+
if (!existsSync(path)) return {};
|
|
1292
1364
|
try {
|
|
1293
1365
|
const pkg = JSON.parse(readFileSync(path, "utf8"));
|
|
1294
|
-
|
|
1366
|
+
return {
|
|
1295
1367
|
...pkg.dependencies,
|
|
1296
1368
|
...pkg.devDependencies
|
|
1297
1369
|
};
|
|
1298
|
-
return BUNDLERS.find((name) => deps[name]);
|
|
1299
1370
|
} catch {
|
|
1300
|
-
return;
|
|
1371
|
+
return {};
|
|
1301
1372
|
}
|
|
1302
1373
|
}
|
|
1374
|
+
function detectHost(root) {
|
|
1375
|
+
const deps = readDependencies(root);
|
|
1376
|
+
return HOSTS.find((host) => deps[host.dep]);
|
|
1377
|
+
}
|
|
1303
1378
|
function configSource(options, typescript) {
|
|
1304
1379
|
const fields = [` sourceLocale: '${options.sourceLocale ?? "en"}',`];
|
|
1305
1380
|
if (options.locales?.length) fields.push(` locales: [${options.locales.map((l) => `'${l}'`).join(", ")}],`);
|
|
@@ -1331,16 +1406,12 @@ function init(options = {}) {
|
|
|
1331
1406
|
created.push(label);
|
|
1332
1407
|
}
|
|
1333
1408
|
}
|
|
1334
|
-
const
|
|
1335
|
-
const next = [];
|
|
1336
|
-
if (bundler === "astro") next.push("install the integration: pnpm add -D @verbaly/astro", "add verbaly() to the integrations in astro.config");
|
|
1337
|
-
else if (bundler === "vite") next.push("install the plugin: pnpm add -D @verbaly/vite", "add verbaly() to the plugins in vite.config");
|
|
1338
|
-
else if (bundler) next.push("install the plugin: pnpm add -D @verbaly/unplugin", `add the verbaly ${bundler} plugin to your build config`);
|
|
1339
|
-
else next.push("run \"verbaly extract\" after writing your first t`…` message");
|
|
1409
|
+
const host = detectHost(root);
|
|
1410
|
+
const next = host ? [`pnpm add -D ${host.pkg}`, host.wire] : ["run \"verbaly extract\" after writing your first t`…` message"];
|
|
1340
1411
|
return {
|
|
1341
1412
|
created,
|
|
1342
1413
|
skipped,
|
|
1343
|
-
|
|
1414
|
+
host: host?.name,
|
|
1344
1415
|
configFile,
|
|
1345
1416
|
next
|
|
1346
1417
|
};
|
|
@@ -1386,11 +1457,11 @@ async function doctor(cfg) {
|
|
|
1386
1457
|
}
|
|
1387
1458
|
try {
|
|
1388
1459
|
const parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
1389
|
-
const bad =
|
|
1460
|
+
const bad = badLeaf(parsed);
|
|
1390
1461
|
if (bad) {
|
|
1391
1462
|
catalogsHealthy = false;
|
|
1392
|
-
error(`locale ${locale}`, `${rel(file)} has a non-string value at "${bad
|
|
1393
|
-
} else catalogs[locale] = parsed;
|
|
1463
|
+
error(`locale ${locale}`, `${rel(file)} has a non-string value at "${bad}"`, "catalog values are text (groups of text are fine); fix the value");
|
|
1464
|
+
} else catalogs[locale] = flatten(parsed);
|
|
1394
1465
|
} catch {
|
|
1395
1466
|
catalogsHealthy = false;
|
|
1396
1467
|
error(`locale ${locale}`, `${rel(file)} is not valid JSON`, "repair the file (or delete it and run `npx verbaly extract`)");
|
|
@@ -1400,21 +1471,22 @@ async function doctor(cfg) {
|
|
|
1400
1471
|
}
|
|
1401
1472
|
const source = catalogs[cfg.sourceLocale];
|
|
1402
1473
|
if (source && Object.keys(source).length === 0) warn("source", `source catalog ${cfg.sourceLocale}.json is empty`, "write your first t`…` message and run `npx verbaly extract`");
|
|
1403
|
-
const deps =
|
|
1404
|
-
const
|
|
1405
|
-
const
|
|
1406
|
-
if (!
|
|
1407
|
-
else if (
|
|
1408
|
-
else
|
|
1409
|
-
|
|
1410
|
-
if (source
|
|
1474
|
+
const deps = readDependencies(cfg.root);
|
|
1475
|
+
const host = detectHost(cfg.root);
|
|
1476
|
+
const installed = WIRING_PACKAGES.find((pkg) => deps[pkg]);
|
|
1477
|
+
if (!host) ok("plugin", "no bundler detected, the CLI flow (extract/check) applies");
|
|
1478
|
+
else if (installed) ok("plugin", `${installed} installed for ${host.name}`);
|
|
1479
|
+
else warn("plugin", `${host.name} detected but ${host.pkg} is not installed`, `pnpm add -D ${host.pkg} and ${host.wire}`);
|
|
1480
|
+
const scanning = cfg.include.length > 0;
|
|
1481
|
+
if (!scanning) ok("sources", "source scanning is off (include: []), the catalogs are the source of truth");
|
|
1482
|
+
if (source && scanning && cfg.dts !== false) {
|
|
1411
1483
|
const dtsPath = cfg.dts ?? join(cfg.root, "verbaly.d.ts");
|
|
1412
1484
|
if (!existsSync(dtsPath)) warn("types", "verbaly.d.ts has not been generated", "run `npx verbaly extract`");
|
|
1413
1485
|
else if (readFileSync(dtsPath, "utf8") !== generateDts(source)) warn("types", "verbaly.d.ts is stale", "run `npx verbaly extract`");
|
|
1414
1486
|
else ok("types", "verbaly.d.ts is up to date");
|
|
1415
1487
|
}
|
|
1416
1488
|
const registry = await extractProject(cfg);
|
|
1417
|
-
if (source) {
|
|
1489
|
+
if (source && scanning) {
|
|
1418
1490
|
const extracted = registry.messages();
|
|
1419
1491
|
const used = registry.usedKeys();
|
|
1420
1492
|
const orphans = Object.keys(source).filter((key) => !extracted.has(key) && !used.has(key));
|
|
@@ -1428,6 +1500,13 @@ async function doctor(cfg) {
|
|
|
1428
1500
|
const locales = [...new Set(result.missing.map((m) => m.locale))];
|
|
1429
1501
|
warn("translations", `${result.missing.length} missing ${result.missing.length === 1 ? "translation" : "translations"} (${locales.join(", ")})`, "run `npx verbaly translate` or fill the catalogs (`npx verbaly check` for details)");
|
|
1430
1502
|
}
|
|
1503
|
+
const broken = result.broken.filter((entry) => entry.severity === "error");
|
|
1504
|
+
if (broken.length > 0) {
|
|
1505
|
+
const locales = [...new Set(broken.map((b) => b.locale))];
|
|
1506
|
+
error("translations", `${broken.length} broken ${broken.length === 1 ? "translation" : "translations"} (${locales.join(", ")}): present but not rendering what the source renders`, "run `npx verbaly check` to read what each one lost");
|
|
1507
|
+
}
|
|
1508
|
+
const warnings = result.broken.filter((entry) => entry.severity === "warning");
|
|
1509
|
+
if (warnings.length > 0) warn("translations", `${warnings.length} structural ${warnings.length === 1 ? "warning" : "warnings"} (plural forms a language asks for)`, "run `npx verbaly check` to read them, they never fail the build");
|
|
1431
1510
|
if (result.ok) ok("translations", "all translations complete");
|
|
1432
1511
|
}
|
|
1433
1512
|
return {
|
|
@@ -1439,15 +1518,13 @@ function preview(keys) {
|
|
|
1439
1518
|
const head = keys.slice(0, PREVIEW).join(", ");
|
|
1440
1519
|
return keys.length > PREVIEW ? `${head}, …` : head;
|
|
1441
1520
|
}
|
|
1442
|
-
function
|
|
1443
|
-
|
|
1444
|
-
const
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
} catch {
|
|
1450
|
-
return {};
|
|
1521
|
+
function badLeaf(tree, prefix = "") {
|
|
1522
|
+
for (const [key, value] of Object.entries(tree)) {
|
|
1523
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
1524
|
+
if (typeof value === "string") continue;
|
|
1525
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return path;
|
|
1526
|
+
const bad = badLeaf(value, path);
|
|
1527
|
+
if (bad) return bad;
|
|
1451
1528
|
}
|
|
1452
1529
|
}
|
|
1453
1530
|
//#endregion
|
|
@@ -2451,20 +2528,22 @@ function decodeEntities(text) {
|
|
|
2451
2528
|
//#endregion
|
|
2452
2529
|
//#region src/status.ts
|
|
2453
2530
|
function status(cfg, catalogs, registry, drafts = {}) {
|
|
2454
|
-
const source = catalogs[cfg.sourceLocale] ?? {};
|
|
2455
|
-
const needed = /* @__PURE__ */ new Set([...registry.messages().keys(), ...Object.keys(source)]);
|
|
2456
|
-
const live = effectiveDrafts(drafts, catalogs);
|
|
2457
2531
|
const extracted = registry.messages();
|
|
2532
|
+
const flat = {};
|
|
2533
|
+
for (const locale of cfg.locales) flat[locale] = flatten(catalogs[locale] ?? {});
|
|
2534
|
+
const source = flat[cfg.sourceLocale] ?? {};
|
|
2535
|
+
const needed = /* @__PURE__ */ new Set([...extracted.keys(), ...Object.keys(source)]);
|
|
2536
|
+
const live = effectiveDrafts(drafts, flat);
|
|
2458
2537
|
const locales = [];
|
|
2459
2538
|
for (const locale of cfg.locales) {
|
|
2460
2539
|
if (locale === cfg.sourceLocale) continue;
|
|
2540
|
+
const catalog = flat[locale] ?? {};
|
|
2461
2541
|
let translated = 0;
|
|
2462
|
-
for (const key of needed) if (
|
|
2542
|
+
for (const key of needed) if (catalog[key]) translated += 1;
|
|
2463
2543
|
let broken = 0;
|
|
2464
|
-
const
|
|
2465
|
-
for (const [key, text] of Object.entries(flatten(catalogs[locale] ?? {}))) {
|
|
2544
|
+
for (const [key, text] of Object.entries(catalog)) {
|
|
2466
2545
|
if (!text) continue;
|
|
2467
|
-
const from =
|
|
2546
|
+
const from = source[key] ?? extracted.get(key)?.message;
|
|
2468
2547
|
if ([...validateMessage(text, locale), ...from ? validatePair(from, text) : []].some((issue) => issue.severity === "error")) broken += 1;
|
|
2469
2548
|
}
|
|
2470
2549
|
locales.push({
|
|
@@ -2750,6 +2829,6 @@ function line(node) {
|
|
|
2750
2829
|
return node.loc?.start?.line ?? 1;
|
|
2751
2830
|
}
|
|
2752
2831
|
//#endregion
|
|
2753
|
-
export { DRAFTS_FILE, LOCALE_MODULE_PREFIX, MessageRegistry, PLURAL_CATEGORIES, PSEUDO_LOCALE, RESOLVED_VIRTUAL_ID, SFC_FILE_RE, SOURCE_FILE_RE, VIRTUAL_ID, analyze, analyzeFile, analyzeSfc, catalogPath, check, claudeProvider, clearDrafts, collectOrigins, collectParams, createSourceFilter,
|
|
2832
|
+
export { DRAFTS_FILE, LOCALE_MODULE_PREFIX, MessageRegistry, PLURAL_CATEGORIES, PSEUDO_LOCALE, RESOLVED_VIRTUAL_ID, SFC_FILE_RE, SOURCE_FILE_RE, VIRTUAL_ID, WIRING_PACKAGES, analyze, analyzeFile, analyzeSfc, catalogPath, check, checkNextSteps, claudeProvider, clearDrafts, collectOrigins, collectParams, createSourceFilter, detectHost, doctor, effectiveDrafts, exportCatalogs, extractProject, findConfigFile, formatCheckResult, formatCheckWarnings, formatStatusResult, gatePasses, generateDts, generateLocaleModule, generateRuntimeModule, githubCheckAnnotations, importCatalogs, init, isMobileFormat, isTransformTarget, loadCatalogs, loadConfig, loadConfigFile, loadDrafts, loadVirtualModule, markDrafts, parseExchangeFile, pruneCatalogs, pseudoCatalogs, pseudoLocalize, readCatalog, readDependencies, renderHtml, renderParamType, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, serializeCatalog, stableKey, status, structureMatches, syncCatalogs, targetLocales, transformCode, transformSource, translateCatalogs, validateMessage, validatePair, watchProject, wrapCode, wrapProject, writeCatalog, writeDts };
|
|
2754
2833
|
|
|
2755
2834
|
//# sourceMappingURL=index.js.map
|