@verbaly/compiler 0.29.0 → 0.30.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/dist/cli.js +0 -0
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.js +229 -40
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -128,6 +128,16 @@ declare class MessageRegistry {
|
|
|
128
128
|
origins(): Map<string, string[]>;
|
|
129
129
|
}
|
|
130
130
|
//#endregion
|
|
131
|
+
//#region src/validate.d.ts
|
|
132
|
+
declare const PLURAL_CATEGORIES: Set<string>;
|
|
133
|
+
type IssueSeverity = 'error' | 'warning';
|
|
134
|
+
interface StructureIssue {
|
|
135
|
+
severity: IssueSeverity;
|
|
136
|
+
message: string;
|
|
137
|
+
}
|
|
138
|
+
declare function validateMessage(message: string, locale?: string): StructureIssue[];
|
|
139
|
+
declare function validatePair(source: string, translated: string): StructureIssue[];
|
|
140
|
+
//#endregion
|
|
131
141
|
//#region src/check.d.ts
|
|
132
142
|
interface MissingEntry {
|
|
133
143
|
locale: string;
|
|
@@ -138,13 +148,21 @@ interface UnknownEntry {
|
|
|
138
148
|
key: string;
|
|
139
149
|
files: string[];
|
|
140
150
|
}
|
|
151
|
+
interface BrokenEntry {
|
|
152
|
+
locale: string;
|
|
153
|
+
key: string;
|
|
154
|
+
severity: IssueSeverity;
|
|
155
|
+
issue: string;
|
|
156
|
+
}
|
|
141
157
|
interface CheckResult {
|
|
142
158
|
ok: boolean;
|
|
143
159
|
missing: MissingEntry[];
|
|
144
160
|
unknown: UnknownEntry[];
|
|
161
|
+
broken: BrokenEntry[];
|
|
145
162
|
}
|
|
146
163
|
declare function check(cfg: ResolvedConfig, catalogs: Catalogs, registry: MessageRegistry): CheckResult;
|
|
147
164
|
declare function formatCheckResult(result: CheckResult): string;
|
|
165
|
+
declare function formatCheckWarnings(result: CheckResult): string;
|
|
148
166
|
declare function githubCheckAnnotations(result: CheckResult, registry: MessageRegistry, root: string): string[];
|
|
149
167
|
//#endregion
|
|
150
168
|
//#region src/codegen.d.ts
|
|
@@ -337,6 +355,7 @@ interface LocaleStatus {
|
|
|
337
355
|
translated: number;
|
|
338
356
|
total: number;
|
|
339
357
|
drafts: number;
|
|
358
|
+
broken: number;
|
|
340
359
|
}
|
|
341
360
|
interface StatusResult {
|
|
342
361
|
messages: number;
|
|
@@ -383,5 +402,5 @@ interface WrapCodeResult {
|
|
|
383
402
|
}
|
|
384
403
|
declare function wrapCode(code: string, file: string): WrapCodeResult;
|
|
385
404
|
//#endregion
|
|
386
|
-
export { type Alternate, type Analysis, type AnalyzeOptions, 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, LOCALE_MODULE_PREFIX, type LocaleStatus, MessageRegistry, type MissingEntry, type MobileFormat, 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 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, detectBundler, doctor, effectiveDrafts, exportCatalogs, extractProject, findConfigFile, formatCheckResult, formatStatusResult, generateDts, generateLocaleModule, generateRuntimeModule, githubCheckAnnotations, importCatalogs, init, isMobileFormat, isTransformTarget, loadCatalogs, loadConfig, loadConfigFile, loadDrafts, loadVirtualModule, markDrafts, parseExchangeFile, pruneCatalogs, pseudoCatalogs, pseudoLocalize, readCatalog, renderHtml, renderParamType, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, serializeCatalog, stableKey, status, structureMatches, syncCatalogs, targetLocales, transformCode, transformSource, translateCatalogs, watchProject, wrapCode, wrapProject, writeCatalog, writeDts };
|
|
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, detectBundler, doctor, effectiveDrafts, exportCatalogs, extractProject, findConfigFile, formatCheckResult, formatCheckWarnings, formatStatusResult, generateDts, generateLocaleModule, generateRuntimeModule, githubCheckAnnotations, importCatalogs, init, isMobileFormat, isTransformTarget, loadCatalogs, loadConfig, loadConfigFile, loadDrafts, loadVirtualModule, markDrafts, parseExchangeFile, pruneCatalogs, pseudoCatalogs, pseudoLocalize, readCatalog, renderHtml, renderParamType, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, serializeCatalog, stableKey, status, structureMatches, syncCatalogs, targetLocales, transformCode, transformSource, translateCatalogs, validateMessage, validatePair, watchProject, wrapCode, wrapProject, writeCatalog, writeDts };
|
|
387
406
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { parse } from "@babel/parser";
|
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, watch, writeFileSync } from "node:fs";
|
|
4
4
|
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
5
|
-
import { RICH_TAGS, createVerbaly, localeDirection, normalizeLink, parse as parse$1, parseTags, safeAttribute } from "verbaly";
|
|
5
|
+
import { RICH_TAGS, createVerbaly, flatten, localeDirection, normalizeLink, parse as parse$1, parseTags, safeAttribute } from "verbaly";
|
|
6
6
|
import { pathToFileURL } from "node:url";
|
|
7
7
|
import picomatch from "picomatch";
|
|
8
8
|
import MagicString from "magic-string";
|
|
@@ -42,7 +42,7 @@ function analyze(code, file, options = {}) {
|
|
|
42
42
|
});
|
|
43
43
|
const tagged = [];
|
|
44
44
|
const usedKeys = [];
|
|
45
|
-
walk(ast.program, (node) => {
|
|
45
|
+
walk$1(ast.program, (node) => {
|
|
46
46
|
if (node.type === "TaggedTemplateExpression") {
|
|
47
47
|
const tag = node.tag;
|
|
48
48
|
const explicit = explicitId(tag, names);
|
|
@@ -206,7 +206,7 @@ function selfClosedSource(code, opening) {
|
|
|
206
206
|
}
|
|
207
207
|
function containsTaggedT(node, names) {
|
|
208
208
|
let found = false;
|
|
209
|
-
walk(node, (n) => {
|
|
209
|
+
walk$1(node, (n) => {
|
|
210
210
|
if (n.type !== "TaggedTemplateExpression") return;
|
|
211
211
|
const tag = n.tag;
|
|
212
212
|
if (isTReference(tag, names) || explicitId(tag, names)) found = true;
|
|
@@ -271,14 +271,14 @@ function uniqueName(base, source, taken) {
|
|
|
271
271
|
taken.set(name, source);
|
|
272
272
|
return name;
|
|
273
273
|
}
|
|
274
|
-
function walk(node, visit) {
|
|
274
|
+
function walk$1(node, visit) {
|
|
275
275
|
visit(node);
|
|
276
276
|
for (const key in node) {
|
|
277
277
|
if (SKIP_KEYS.has(key)) continue;
|
|
278
278
|
const value = node[key];
|
|
279
279
|
if (Array.isArray(value)) {
|
|
280
|
-
for (const item of value) if (isNode(item)) walk(item, visit);
|
|
281
|
-
} else if (isNode(value)) walk(value, visit);
|
|
280
|
+
for (const item of value) if (isNode(item)) walk$1(item, visit);
|
|
281
|
+
} else if (isNode(value)) walk$1(value, visit);
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
284
|
function isNode(value) {
|
|
@@ -466,6 +466,158 @@ function writeCatalog(cfg, locale, catalog) {
|
|
|
466
466
|
return serialized;
|
|
467
467
|
}
|
|
468
468
|
//#endregion
|
|
469
|
+
//#region src/validate.ts
|
|
470
|
+
const PLURAL_CATEGORIES = /* @__PURE__ */ new Set([
|
|
471
|
+
"zero",
|
|
472
|
+
"one",
|
|
473
|
+
"two",
|
|
474
|
+
"few",
|
|
475
|
+
"many"
|
|
476
|
+
]);
|
|
477
|
+
const EXACT = /^=\d+$/;
|
|
478
|
+
function shapes(message) {
|
|
479
|
+
const out = /* @__PURE__ */ new Map();
|
|
480
|
+
walk(parse$1(message), out);
|
|
481
|
+
return out;
|
|
482
|
+
}
|
|
483
|
+
function walk(nodes, out) {
|
|
484
|
+
for (const node of nodes) {
|
|
485
|
+
if (node.kind !== "param" || !node.variants) continue;
|
|
486
|
+
const selectors = node.variants.map(([key]) => key);
|
|
487
|
+
if (!out.has(node.name)) out.set(node.name, {
|
|
488
|
+
selectors,
|
|
489
|
+
plural: selectors.some((key) => PLURAL_CATEGORIES.has(key)),
|
|
490
|
+
ordinal: node.ordinal === true
|
|
491
|
+
});
|
|
492
|
+
for (const [, body] of node.variants) walk(body, out);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
function paramNames(message) {
|
|
496
|
+
const names = /* @__PURE__ */ new Set();
|
|
497
|
+
collect(parse$1(message), names);
|
|
498
|
+
return [...names].sort();
|
|
499
|
+
}
|
|
500
|
+
function collect(nodes, out) {
|
|
501
|
+
for (const node of nodes) {
|
|
502
|
+
if (node.kind !== "param") continue;
|
|
503
|
+
out.add(node.name);
|
|
504
|
+
if (node.variants) for (const [, body] of node.variants) collect(body, out);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
const TAG = /<(\/?)([a-zA-Z][\w-]*)(\/?)>/g;
|
|
508
|
+
function tagTokens(message) {
|
|
509
|
+
const out = [];
|
|
510
|
+
for (const match of message.matchAll(TAG)) out.push(`${match[1]}${match[2]}${match[3]}`);
|
|
511
|
+
return out.sort();
|
|
512
|
+
}
|
|
513
|
+
function surplus(a, b) {
|
|
514
|
+
const rest = [...b];
|
|
515
|
+
const out = [];
|
|
516
|
+
for (const item of a) {
|
|
517
|
+
const at = rest.indexOf(item);
|
|
518
|
+
if (at < 0) out.push(item);
|
|
519
|
+
else rest.splice(at, 1);
|
|
520
|
+
}
|
|
521
|
+
return out;
|
|
522
|
+
}
|
|
523
|
+
function list(items) {
|
|
524
|
+
return items.length > 1 ? `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}` : items[0];
|
|
525
|
+
}
|
|
526
|
+
function validateMessage(message, locale) {
|
|
527
|
+
const issues = [];
|
|
528
|
+
for (const [name, shape] of shapes(message)) {
|
|
529
|
+
if (!shape.plural) continue;
|
|
530
|
+
if (!shape.selectors.includes("other")) {
|
|
531
|
+
issues.push({
|
|
532
|
+
severity: "error",
|
|
533
|
+
message: `the plural block for {${name}} has no "other" case, so any count it does not list renders empty`
|
|
534
|
+
});
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
if (!locale) continue;
|
|
538
|
+
const missing = reachableCategories(locale, shape.ordinal).filter((category) => category !== "other" && !shape.selectors.includes(category));
|
|
539
|
+
if (missing.length > 0) issues.push({
|
|
540
|
+
severity: "warning",
|
|
541
|
+
message: `${locale} also needs the ${list(missing)} plural ${missing.length > 1 ? "forms" : "form"} for {${name}}`
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
return issues;
|
|
545
|
+
}
|
|
546
|
+
function validatePair(source, translated) {
|
|
547
|
+
const issues = [];
|
|
548
|
+
const lostParams = surplus(paramNames(source), paramNames(translated));
|
|
549
|
+
const newParams = surplus(paramNames(translated), paramNames(source));
|
|
550
|
+
if (lostParams.length > 0) issues.push({
|
|
551
|
+
severity: "error",
|
|
552
|
+
message: `${list(lostParams.map((name) => `{${name}}`))} ${lostParams.length > 1 ? "are" : "is"} missing, so ${lostParams.length > 1 ? "their values" : "its value"} never reaches the text`
|
|
553
|
+
});
|
|
554
|
+
if (newParams.length > 0) issues.push({
|
|
555
|
+
severity: "error",
|
|
556
|
+
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
|
+
});
|
|
558
|
+
const lostTags = tagReport(surplus(tagTokens(source), tagTokens(translated)));
|
|
559
|
+
const newTags = tagReport(surplus(tagTokens(translated), tagTokens(source)));
|
|
560
|
+
if (lostTags.length > 0) issues.push({
|
|
561
|
+
severity: "error",
|
|
562
|
+
message: `${list(lostTags)} ${lostTags.length > 1 ? "are" : "is"} missing from the translation`
|
|
563
|
+
});
|
|
564
|
+
if (newTags.length > 0) issues.push({
|
|
565
|
+
severity: "error",
|
|
566
|
+
message: `${list(newTags)} ${newTags.length > 1 ? "are" : "is"} not in the source message`
|
|
567
|
+
});
|
|
568
|
+
const target = shapes(translated);
|
|
569
|
+
for (const [name, shape] of shapes(source)) {
|
|
570
|
+
const other = target.get(name);
|
|
571
|
+
if (!other) {
|
|
572
|
+
issues.push({
|
|
573
|
+
severity: "error",
|
|
574
|
+
message: `the ${shape.plural ? "plural" : "select"} block for {${name}} was flattened into plain text`
|
|
575
|
+
});
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
if (shape.selectors.includes("other") && !other.selectors.includes("other") && !other.plural) issues.push({
|
|
579
|
+
severity: "error",
|
|
580
|
+
message: `the "other" case for {${name}} is missing, so unlisted values render empty`
|
|
581
|
+
});
|
|
582
|
+
const lostExact = shape.selectors.filter((key) => EXACT.test(key)).filter((key) => !other.selectors.includes(key));
|
|
583
|
+
if (lostExact.length > 0) issues.push({
|
|
584
|
+
severity: "warning",
|
|
585
|
+
message: `the ${list(lostExact)} ${lostExact.length > 1 ? "cases" : "case"} for {${name}} ${lostExact.length > 1 ? "are" : "is"} missing, so ${lostExact.length > 1 ? "those counts" : "that count"} falls back to "other"`
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
return issues;
|
|
589
|
+
}
|
|
590
|
+
function tagReport(tokens) {
|
|
591
|
+
const out = [];
|
|
592
|
+
const seen = /* @__PURE__ */ new Set();
|
|
593
|
+
for (const token of tokens) {
|
|
594
|
+
const name = token.replaceAll("/", "");
|
|
595
|
+
if (seen.has(name)) continue;
|
|
596
|
+
seen.add(name);
|
|
597
|
+
out.push(token.endsWith("/") ? `<${name}/>` : `<${name}>`);
|
|
598
|
+
}
|
|
599
|
+
return out;
|
|
600
|
+
}
|
|
601
|
+
const COUNT_PROBE = 200;
|
|
602
|
+
const reachable = /* @__PURE__ */ new Map();
|
|
603
|
+
function reachableCategories(locale, ordinal) {
|
|
604
|
+
const type = ordinal ? "ordinal" : "cardinal";
|
|
605
|
+
const cacheKey = `${locale}${type}`;
|
|
606
|
+
const hit = reachable.get(cacheKey);
|
|
607
|
+
if (hit) return hit;
|
|
608
|
+
let out;
|
|
609
|
+
try {
|
|
610
|
+
const rules = new Intl.PluralRules(locale, { type });
|
|
611
|
+
const seen = /* @__PURE__ */ new Set();
|
|
612
|
+
for (let n = 0; n <= COUNT_PROBE; n++) seen.add(rules.select(n));
|
|
613
|
+
out = [...seen];
|
|
614
|
+
} catch {
|
|
615
|
+
out = [];
|
|
616
|
+
}
|
|
617
|
+
reachable.set(cacheKey, out);
|
|
618
|
+
return out;
|
|
619
|
+
}
|
|
620
|
+
//#endregion
|
|
469
621
|
//#region src/check.ts
|
|
470
622
|
function check(cfg, catalogs, registry) {
|
|
471
623
|
const source = catalogs[cfg.sourceLocale] ?? {};
|
|
@@ -490,10 +642,35 @@ function check(cfg, catalogs, registry) {
|
|
|
490
642
|
source: source[key] ?? extracted.get(key)?.message
|
|
491
643
|
});
|
|
492
644
|
}
|
|
645
|
+
const broken = [];
|
|
646
|
+
const add = (locale, key, issues) => {
|
|
647
|
+
for (const issue of issues) broken.push({
|
|
648
|
+
locale,
|
|
649
|
+
key,
|
|
650
|
+
severity: issue.severity,
|
|
651
|
+
issue: issue.message
|
|
652
|
+
});
|
|
653
|
+
};
|
|
654
|
+
const sourceFlat = flatten(source);
|
|
655
|
+
for (const key of needed) {
|
|
656
|
+
const text = sourceFlat[key] ?? extracted.get(key)?.message;
|
|
657
|
+
if (text) sourceFlat[key] = text;
|
|
658
|
+
}
|
|
659
|
+
for (const [key, text] of Object.entries(sourceFlat)) add(cfg.sourceLocale, key, validateMessage(text, cfg.sourceLocale));
|
|
660
|
+
for (const locale of cfg.locales) {
|
|
661
|
+
if (locale === cfg.sourceLocale) continue;
|
|
662
|
+
for (const [key, translated] of Object.entries(flatten(catalogs[locale] ?? {}))) {
|
|
663
|
+
if (!translated) continue;
|
|
664
|
+
add(locale, key, validateMessage(translated, locale));
|
|
665
|
+
const text = sourceFlat[key];
|
|
666
|
+
if (text) add(locale, key, validatePair(text, translated));
|
|
667
|
+
}
|
|
668
|
+
}
|
|
493
669
|
return {
|
|
494
|
-
ok: missing.length === 0 && unknown.length === 0,
|
|
670
|
+
ok: missing.length === 0 && unknown.length === 0 && !broken.some((entry) => entry.severity === "error"),
|
|
495
671
|
missing,
|
|
496
|
-
unknown
|
|
672
|
+
unknown,
|
|
673
|
+
broken
|
|
497
674
|
};
|
|
498
675
|
}
|
|
499
676
|
function formatCheckResult(result) {
|
|
@@ -509,8 +686,16 @@ function formatCheckResult(result) {
|
|
|
509
686
|
lines.push("unknown keys (not in any catalog):");
|
|
510
687
|
for (const entry of result.unknown) lines.push(` ${entry.key} (used in ${entry.files.join(", ")})`);
|
|
511
688
|
}
|
|
689
|
+
const errors = result.broken.filter((entry) => entry.severity === "error");
|
|
690
|
+
if (errors.length > 0) {
|
|
691
|
+
lines.push("broken translations:");
|
|
692
|
+
for (const entry of errors) lines.push(` [${entry.locale}] ${entry.key}: ${entry.issue}`);
|
|
693
|
+
}
|
|
512
694
|
return lines.join("\n");
|
|
513
695
|
}
|
|
696
|
+
function formatCheckWarnings(result) {
|
|
697
|
+
return result.broken.filter((entry) => entry.severity === "warning").map((entry) => ` [${entry.locale}] ${entry.key}: ${entry.issue}`).join("\n");
|
|
698
|
+
}
|
|
514
699
|
function truncate(text, max) {
|
|
515
700
|
return text.length > max ? text.slice(0, max - 1) + "…" : text;
|
|
516
701
|
}
|
|
@@ -551,6 +736,19 @@ function githubCheckAnnotations(result, registry, root) {
|
|
|
551
736
|
const file = entry.files[0];
|
|
552
737
|
lines.push(file ? `::error file=${escapeProperty(relative(root, file).replaceAll("\\", "/"))}::${text}` : `::error::${text}`);
|
|
553
738
|
}
|
|
739
|
+
for (const entry of result.broken) {
|
|
740
|
+
const origin = messages.get(entry.key);
|
|
741
|
+
const text = escapeData(`[${entry.locale}] ${entry.key}: ${entry.issue}`);
|
|
742
|
+
const command = entry.severity === "error" ? "error" : "warning";
|
|
743
|
+
if (!origin) {
|
|
744
|
+
lines.push(`::${command}::${text}`);
|
|
745
|
+
continue;
|
|
746
|
+
}
|
|
747
|
+
const file = relative(root, origin.file).replaceAll("\\", "/");
|
|
748
|
+
const content = readSource(origin.file);
|
|
749
|
+
const line = content === void 0 ? void 0 : lineAt(content, origin.start);
|
|
750
|
+
lines.push(`::${command} file=${escapeProperty(file)}${line ? `,line=${line}` : ""}::${text}`);
|
|
751
|
+
}
|
|
554
752
|
return lines;
|
|
555
753
|
}
|
|
556
754
|
function lineAt(content, offset) {
|
|
@@ -567,13 +765,6 @@ function escapeProperty(text) {
|
|
|
567
765
|
}
|
|
568
766
|
//#endregion
|
|
569
767
|
//#region src/params.ts
|
|
570
|
-
const PLURAL_KEYS = /* @__PURE__ */ new Set([
|
|
571
|
-
"zero",
|
|
572
|
-
"one",
|
|
573
|
-
"two",
|
|
574
|
-
"few",
|
|
575
|
-
"many"
|
|
576
|
-
]);
|
|
577
768
|
const NUMBER_FORMATS = /* @__PURE__ */ new Set([
|
|
578
769
|
"number",
|
|
579
770
|
"integer",
|
|
@@ -593,7 +784,7 @@ function visit(nodes, out) {
|
|
|
593
784
|
out.set(node.name, types);
|
|
594
785
|
if (node.variants) {
|
|
595
786
|
for (const [key, body] of node.variants) {
|
|
596
|
-
if (
|
|
787
|
+
if (PLURAL_CATEGORIES.has(key) || /^=\d+$/.test(key)) types.add("number");
|
|
597
788
|
else if (key !== "other") types.add("string");
|
|
598
789
|
visit(body, out);
|
|
599
790
|
}
|
|
@@ -1712,24 +1903,12 @@ async function resolveProvider(cfg, model) {
|
|
|
1712
1903
|
return claudeProvider({ model: model ?? cfg.translate.model });
|
|
1713
1904
|
}
|
|
1714
1905
|
function structureMatches(source, translated) {
|
|
1715
|
-
return sameMembers(paramNames(source), paramNames(translated)) && sameMembers(tagTokens(source), tagTokens(translated));
|
|
1716
|
-
}
|
|
1717
|
-
function paramNames(message) {
|
|
1718
1906
|
try {
|
|
1719
|
-
return [...
|
|
1907
|
+
return ![...validateMessage(translated), ...validatePair(source, translated)].some((issue) => issue.severity === "error");
|
|
1720
1908
|
} catch {
|
|
1721
|
-
return
|
|
1909
|
+
return false;
|
|
1722
1910
|
}
|
|
1723
1911
|
}
|
|
1724
|
-
const TAG = /<(\/?)([a-zA-Z][\w-]*)(\/?)>/g;
|
|
1725
|
-
function tagTokens(message) {
|
|
1726
|
-
const out = [];
|
|
1727
|
-
for (const match of message.matchAll(TAG)) out.push(`${match[1]}${match[2]}${match[3]}`);
|
|
1728
|
-
return out.sort();
|
|
1729
|
-
}
|
|
1730
|
-
function sameMembers(a, b) {
|
|
1731
|
-
return a.length === b.length && a.every((value, i) => value === b[i]);
|
|
1732
|
-
}
|
|
1733
1912
|
//#endregion
|
|
1734
1913
|
//#region src/exchange.ts
|
|
1735
1914
|
function isMobileFormat(format) {
|
|
@@ -2275,16 +2454,25 @@ function status(cfg, catalogs, registry, drafts = {}) {
|
|
|
2275
2454
|
const source = catalogs[cfg.sourceLocale] ?? {};
|
|
2276
2455
|
const needed = /* @__PURE__ */ new Set([...registry.messages().keys(), ...Object.keys(source)]);
|
|
2277
2456
|
const live = effectiveDrafts(drafts, catalogs);
|
|
2457
|
+
const extracted = registry.messages();
|
|
2278
2458
|
const locales = [];
|
|
2279
2459
|
for (const locale of cfg.locales) {
|
|
2280
2460
|
if (locale === cfg.sourceLocale) continue;
|
|
2281
2461
|
let translated = 0;
|
|
2282
2462
|
for (const key of needed) if (catalogs[locale]?.[key]) translated += 1;
|
|
2463
|
+
let broken = 0;
|
|
2464
|
+
const flatSource = flatten(source ?? {});
|
|
2465
|
+
for (const [key, text] of Object.entries(flatten(catalogs[locale] ?? {}))) {
|
|
2466
|
+
if (!text) continue;
|
|
2467
|
+
const from = flatSource[key] ?? extracted.get(key)?.message;
|
|
2468
|
+
if ([...validateMessage(text, locale), ...from ? validatePair(from, text) : []].some((issue) => issue.severity === "error")) broken += 1;
|
|
2469
|
+
}
|
|
2283
2470
|
locales.push({
|
|
2284
2471
|
locale,
|
|
2285
2472
|
translated,
|
|
2286
2473
|
total: needed.size,
|
|
2287
|
-
drafts: live[locale]?.length ?? 0
|
|
2474
|
+
drafts: live[locale]?.length ?? 0,
|
|
2475
|
+
broken
|
|
2288
2476
|
});
|
|
2289
2477
|
}
|
|
2290
2478
|
return {
|
|
@@ -2299,11 +2487,12 @@ function formatStatusResult(result) {
|
|
|
2299
2487
|
lines.push(" no target locales (add locales to your config)");
|
|
2300
2488
|
return lines.join("\n");
|
|
2301
2489
|
}
|
|
2302
|
-
for (const { locale, translated, total, drafts } of result.locales) {
|
|
2490
|
+
for (const { locale, translated, total, drafts, broken } of result.locales) {
|
|
2303
2491
|
const pct = total === 0 ? 100 : Math.floor(translated / total * 100);
|
|
2304
|
-
const mark = translated === total ? " ✓" : "";
|
|
2305
|
-
const
|
|
2306
|
-
|
|
2492
|
+
const mark = translated === total && broken === 0 ? " ✓" : "";
|
|
2493
|
+
const notes = [drafts > 0 ? `${drafts} unreviewed` : "", broken > 0 ? `${broken} broken` : ""].filter(Boolean);
|
|
2494
|
+
const note = notes.length > 0 ? `, ${notes.join(", ")}` : "";
|
|
2495
|
+
lines.push(` ${locale}: ${translated}/${total} translated (${pct}%${note})${mark}`);
|
|
2307
2496
|
}
|
|
2308
2497
|
return lines.join("\n");
|
|
2309
2498
|
}
|
|
@@ -2402,7 +2591,7 @@ function wrapCode(code, file) {
|
|
|
2402
2591
|
const s = new MagicString(code);
|
|
2403
2592
|
const visited = /* @__PURE__ */ new Set();
|
|
2404
2593
|
let changed = false;
|
|
2405
|
-
walk(ast, (node) => {
|
|
2594
|
+
walk$1(ast, (node) => {
|
|
2406
2595
|
if (node.type !== "JSXElement" && node.type !== "JSXFragment") return;
|
|
2407
2596
|
if (visited.has(node)) return;
|
|
2408
2597
|
processElement(node);
|
|
@@ -2521,7 +2710,7 @@ function wrapCode(code, file) {
|
|
|
2521
2710
|
return text.length > 60 ? text.slice(0, 59) + "…" : text;
|
|
2522
2711
|
}
|
|
2523
2712
|
function markSubtree(node) {
|
|
2524
|
-
walk(node, (n) => {
|
|
2713
|
+
walk$1(node, (n) => {
|
|
2525
2714
|
if (n.type === "JSXElement" || n.type === "JSXFragment") visited.add(n);
|
|
2526
2715
|
});
|
|
2527
2716
|
}
|
|
@@ -2535,7 +2724,7 @@ function hasVerbalyAttr(opening) {
|
|
|
2535
2724
|
}
|
|
2536
2725
|
function usesT(node) {
|
|
2537
2726
|
let found = false;
|
|
2538
|
-
walk(node, (n) => {
|
|
2727
|
+
walk$1(node, (n) => {
|
|
2539
2728
|
if (n.type === "TaggedTemplateExpression" && isTReference(n.tag, T_NAMES)) found = true;
|
|
2540
2729
|
if (n.type === "CallExpression" && isTReference(n.callee, T_NAMES)) found = true;
|
|
2541
2730
|
});
|
|
@@ -2543,7 +2732,7 @@ function usesT(node) {
|
|
|
2543
2732
|
}
|
|
2544
2733
|
function containsJsx(node) {
|
|
2545
2734
|
let found = false;
|
|
2546
|
-
walk(node, (n) => {
|
|
2735
|
+
walk$1(node, (n) => {
|
|
2547
2736
|
if (n.type === "JSXElement" || n.type === "JSXFragment") found = true;
|
|
2548
2737
|
});
|
|
2549
2738
|
return found;
|
|
@@ -2561,6 +2750,6 @@ function line(node) {
|
|
|
2561
2750
|
return node.loc?.start?.line ?? 1;
|
|
2562
2751
|
}
|
|
2563
2752
|
//#endregion
|
|
2564
|
-
export { DRAFTS_FILE, LOCALE_MODULE_PREFIX, MessageRegistry, PSEUDO_LOCALE, RESOLVED_VIRTUAL_ID, SFC_FILE_RE, SOURCE_FILE_RE, VIRTUAL_ID, analyze, analyzeFile, analyzeSfc, catalogPath, check, claudeProvider, clearDrafts, collectOrigins, collectParams, createSourceFilter, detectBundler, doctor, effectiveDrafts, exportCatalogs, extractProject, findConfigFile, formatCheckResult, formatStatusResult, generateDts, generateLocaleModule, generateRuntimeModule, githubCheckAnnotations, importCatalogs, init, isMobileFormat, isTransformTarget, loadCatalogs, loadConfig, loadConfigFile, loadDrafts, loadVirtualModule, markDrafts, parseExchangeFile, pruneCatalogs, pseudoCatalogs, pseudoLocalize, readCatalog, renderHtml, renderParamType, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, serializeCatalog, stableKey, status, structureMatches, syncCatalogs, targetLocales, transformCode, transformSource, translateCatalogs, watchProject, wrapCode, wrapProject, writeCatalog, writeDts };
|
|
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, detectBundler, doctor, effectiveDrafts, exportCatalogs, extractProject, findConfigFile, formatCheckResult, formatCheckWarnings, formatStatusResult, generateDts, generateLocaleModule, generateRuntimeModule, githubCheckAnnotations, importCatalogs, init, isMobileFormat, isTransformTarget, loadCatalogs, loadConfig, loadConfigFile, loadDrafts, loadVirtualModule, markDrafts, parseExchangeFile, pruneCatalogs, pseudoCatalogs, pseudoLocalize, readCatalog, renderHtml, renderParamType, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, serializeCatalog, stableKey, status, structureMatches, syncCatalogs, targetLocales, transformCode, transformSource, translateCatalogs, validateMessage, validatePair, watchProject, wrapCode, wrapProject, writeCatalog, writeDts };
|
|
2565
2754
|
|
|
2566
2755
|
//# sourceMappingURL=index.js.map
|