@verbaly/compiler 0.70.0 → 0.71.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 +8 -7
- package/dist/cli.js +101 -43
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +90 -42
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -44,12 +44,14 @@ Reads `verbaly.config.{js,mjs,ts,mts,json}` (TS configs need `esbuild` installed
|
|
|
44
44
|
|
|
45
45
|
## 🚦 The gate: `check` in CI, a report in every build
|
|
46
46
|
|
|
47
|
-
`verbaly check` is the only command that exits 1. Run it in CI: it is the strict gate, and it asks
|
|
47
|
+
`verbaly check` is the only command that exits 1. Run it in CI: it is the strict gate, and it asks four questions.
|
|
48
48
|
|
|
49
49
|
**Is every message translated?** A missing key or an empty value fails `check`, so a raw key never reaches a release your CI let through.
|
|
50
50
|
|
|
51
51
|
**Does every key you wrote exist?** A key written in the code has to be in a catalog, however it is spelled (`t('k')`, ``t(`k`)``, `<Trans id={'k'}>`) and also when a `t` under another name reads it. One that is not renders the key itself.
|
|
52
52
|
|
|
53
|
+
**Does every key have one text?** Two `` t.id('k')`…` `` with different texts both render the one written first, by file path, so one place shows a text nobody wrote for it. `check` names every place that disagrees, with its line, and the fix is a key for each text.
|
|
54
|
+
|
|
53
55
|
**Can the translation render what the source renders?** Presence is not correctness. These fail too, each with the reason in plain words:
|
|
54
56
|
|
|
55
57
|
| The translation… | Why it fails |
|
|
@@ -63,13 +65,12 @@ Two more are reported as **warnings** and keep the exit code at 0, because the t
|
|
|
63
65
|
|
|
64
66
|
A third warning is a key that **only a translation has**. It never fails the build either, and the report says which case it is: your code reads it, so the source language shows the raw key there, or nothing reads it and it is dead weight in that language's download (`extract --prune` drops it).
|
|
65
67
|
|
|
66
|
-
|
|
68
|
+
Two more warnings name things that used to happen in silence, each with the file and line to go to:
|
|
67
69
|
|
|
68
|
-
- **One key, two texts.** Two `` t.id('k')`…` `` with different texts both render the one written first, by file path, so the order your files load never picks it. The report lists every place that disagrees.
|
|
69
70
|
- **The catalog and the code disagree.** A text written in your code is the code's: the build ships it, and the source catalog only mirrors it (see [where a text lives](#-where-a-text-lives)).
|
|
70
71
|
- **An outdated translation.** The source text changed after the translation was written, and nobody has looked at the translation since. It is read against the text that ships, the one in your code, so it is caught even before `extract` runs.
|
|
71
72
|
|
|
72
|
-
**A build never stops over a text.** The bundler plugins run the same `check` at the end of every build, say what it found and let the build finish: a missing translation shows in the source language, a key no catalog has shows the key itself, and a broken translation renders differently from
|
|
73
|
+
**A build never stops over a text.** The bundler plugins run the same `check` at the end of every build, say what it found and let the build finish: a missing translation shows in the source language, a key no catalog has shows the key itself, and a broken translation, like a key with two texts, renders differently from what was written, so those come first:
|
|
73
74
|
|
|
74
75
|
```text
|
|
75
76
|
[verbaly] ✗ the build goes on with 1 broken translation, each rendering differently from its source:
|
|
@@ -119,7 +120,7 @@ t(titles[slug]);
|
|
|
119
120
|
|
|
120
121
|
`defineKeys` is detected by name, like `t`. It comes from `virtual:verbaly`, the module generated for your project, which is the one the framework provider already loads.
|
|
121
122
|
|
|
122
|
-
**A translation knows which source text it was written for.** For readable keys, the second and third rows, Verbaly keeps a short fingerprint of the source text and of the translation in
|
|
123
|
+
**A translation knows which source text it was written for.** For readable keys, the second and third rows, Verbaly keeps a short fingerprint of the source text and of the translation in `verbaly.lock`, next to your config. It is taken the moment the translation is written, by `translate`, `import`, Studio or an agent, so a source that changes right after is still caught; `import` takes it from the source text the translator's file carries, so a file made for an older text reads as outdated at once. When the source text changes and the translation does not, the translation is **outdated**: `status`, `check` and `doctor` say so, `review` lists it with both texts, and `review --approve` keeps it if it still holds. Editing the translation clears it on its own. Hash keys never need this, because a new text is a new key.
|
|
123
124
|
|
|
124
125
|
Four details that catch people out:
|
|
125
126
|
|
|
@@ -182,7 +183,7 @@ export default {
|
|
|
182
183
|
|
|
183
184
|
Only the terms a batch actually contains are sent, so a glossary of hundreds never becomes the prompt.
|
|
184
185
|
|
|
185
|
-
**Machine output is a draft until a human says yes.** Everything `translate` writes is recorded in `
|
|
186
|
+
**Machine output is a draft until a human says yes.** Everything `translate` writes is recorded in `verbaly.lock`, the file that also holds the fingerprints above. Like a package manager's lockfile, Verbaly writes it and you commit it, and nobody edits it by hand; the first command that writes it says so. A `.verbaly-state.json` an older version left next to the catalogs moves into it on its own. `verbaly review` lists the drafts with the source text and the translation side by side, `--approve` accepts them (`verbaly review home.title --approve` accepts only the keys you name), and importing a translator's file clears the flag because a human already reviewed it. `import --draft` keeps them as drafts instead, for a file nobody has read yet. An agent that translates on its own saves its work through the MCP tool `verbaly_write_drafts`, which checks it like a provider's and marks it as a draft. `verbaly check --drafts` turns "nothing unreviewed ships" into a CI rule; plain `check` leaves it alone, since a draft has a value and is therefore not missing. `extract` keeps the file in step with the catalogs, so a pruned key takes its draft with it, and the file disappears when there is nothing left in it. It only ever touches the languages it read: `extract --locales es` leaves every other language's drafts and fingerprints as they were. If the file cannot be read, say after a merge conflict, the commands that only read it warn and go on, and the ones that would write drafts stop before writing anything: restore it from git, because deleting it would mark every draft as reviewed.
|
|
186
187
|
|
|
187
188
|
Plug your own provider in `verbaly.config.ts`. In TypeScript, `TranslateProvider` types it for you:
|
|
188
189
|
|
|
@@ -388,7 +389,7 @@ runBuildGate(cfg, registry);
|
|
|
388
389
|
|
|
389
390
|
Call `reportOutsideInclude(cfg)` once when your build starts: it names every file outside `include` that writes a `` t`…` ``, which no build translates. It reads the project itself, so a cached transform never hides one. `writeDts(cfg, catalog)` writes the types where the config resolves them and returns the file and whether it changed.
|
|
390
391
|
|
|
391
|
-
A dev server that writes the catalogs goes through `syncProject`, the same path `extract`, the MCP server and Studio take: it scans (or takes the registry you hold), syncs, writes the catalogs and the types, and keeps
|
|
392
|
+
A dev server that writes the catalogs goes through `syncProject`, the same path `extract`, the MCP server and Studio take: it scans (or takes the registry you hold), syncs, writes the catalogs and the types, and keeps `verbaly.lock` in step, in that order; its `findings` say once when that file first appears. Pass `confirm: true` when your registry is built file by file, so a file that changed on disk unseen is read again before its text is written back. `createDevReporter` then says each of its findings once, says it again if it goes away and comes back, and keeps a long list to a few lines.
|
|
392
393
|
|
|
393
394
|
## License
|
|
394
395
|
|
package/dist/cli.js
CHANGED
|
@@ -1225,6 +1225,10 @@ function formatFinding(finding, root) {
|
|
|
1225
1225
|
case "escaped": return `${sourcePlace(finding.site, root)}: ${finding.slice} renders as literal text, a tagged template has no params (use t(key, params) for a plural or format block, or pass a \${…} value)`;
|
|
1226
1226
|
case "unparsed": return `${sourcePlace(finding, root)}: could not be parsed (${finding.message}), its messages were not extracted`;
|
|
1227
1227
|
case "outdated": return `[${finding.locale}] ${finding.key}: translated from an older source text, update it or keep it with \`npx verbaly review --approve\``;
|
|
1228
|
+
case "lock": {
|
|
1229
|
+
const lock = sourcePlace(finding, root);
|
|
1230
|
+
return finding.from ? `${sourcePlace({ file: finding.from }, root)} moved to ${lock}, next to your config: commit both changes` : `${lock} now keeps the source text each translation was made for and which ones are drafts: commit it with your catalogs`;
|
|
1231
|
+
}
|
|
1228
1232
|
}
|
|
1229
1233
|
}
|
|
1230
1234
|
function findingId(finding) {
|
|
@@ -1236,6 +1240,7 @@ function findingId(finding) {
|
|
|
1236
1240
|
case "positional": return `positional:${finding.site.file}:${finding.params.join(",")}`;
|
|
1237
1241
|
case "escaped": return `escaped:${finding.site.file}:${finding.slice}`;
|
|
1238
1242
|
case "unparsed": return `unparsed:${finding.file}`;
|
|
1243
|
+
case "lock": return `lock:${finding.file}`;
|
|
1239
1244
|
}
|
|
1240
1245
|
}
|
|
1241
1246
|
function createDevReporter(root, print = (line) => console.warn(`[verbaly] ${line}`), cap = 5) {
|
|
@@ -1603,27 +1608,52 @@ function definedOnly(config) {
|
|
|
1603
1608
|
}
|
|
1604
1609
|
//#endregion
|
|
1605
1610
|
//#region src/state.ts
|
|
1606
|
-
const STATE_FILE = "
|
|
1611
|
+
const STATE_FILE = "verbaly.lock";
|
|
1612
|
+
const LOCK_VERSION = 1;
|
|
1613
|
+
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.";
|
|
1614
|
+
const LEGACY_STATE_FILE = ".verbaly-state.json";
|
|
1607
1615
|
const LEGACY_DRAFTS_FILE = ".verbaly-drafts.json";
|
|
1608
|
-
function statePath(cfg
|
|
1609
|
-
return join(cfg.
|
|
1616
|
+
function statePath(cfg) {
|
|
1617
|
+
return join(cfg.root, STATE_FILE);
|
|
1618
|
+
}
|
|
1619
|
+
function legacyPaths(cfg) {
|
|
1620
|
+
return [join(cfg.dir, LEGACY_STATE_FILE), join(cfg.dir, LEGACY_DRAFTS_FILE)];
|
|
1610
1621
|
}
|
|
1611
1622
|
function loadState(cfg) {
|
|
1612
|
-
const
|
|
1613
|
-
if (
|
|
1614
|
-
const
|
|
1615
|
-
|
|
1616
|
-
const state = isObject(current) ? {
|
|
1617
|
-
drafts: readDrafts(current.drafts),
|
|
1618
|
-
fingerprints: readFingerprints(current.fingerprints),
|
|
1619
|
-
migrated: readMigrated(current.migrated)
|
|
1620
|
-
} : {
|
|
1623
|
+
const lock = readObject(statePath(cfg));
|
|
1624
|
+
if (lock) checkVersion(statePath(cfg), lock.version);
|
|
1625
|
+
const [legacyState, legacyDrafts] = legacyPaths(cfg).map(readObject);
|
|
1626
|
+
const state = {
|
|
1621
1627
|
drafts: {},
|
|
1622
1628
|
fingerprints: {}
|
|
1623
1629
|
};
|
|
1624
|
-
|
|
1630
|
+
for (const source of [lock, legacyState]) {
|
|
1631
|
+
if (!source) continue;
|
|
1632
|
+
for (const [locale, keys] of Object.entries(readDrafts(source.drafts))) markDrafts(state.drafts, locale, keys);
|
|
1633
|
+
for (const [locale, stamps] of Object.entries(readFingerprints(source.fingerprints))) {
|
|
1634
|
+
const into = state.fingerprints[locale] ??= emptyCatalog();
|
|
1635
|
+
for (const [key, stamped] of Object.entries(stamps)) if (own(into, key) === void 0) into[key] = stamped;
|
|
1636
|
+
}
|
|
1637
|
+
const migrated = readMigrated(source.migrated);
|
|
1638
|
+
if (migrated) state.migrated = [.../* @__PURE__ */ new Set([...state.migrated ?? [], ...migrated])];
|
|
1639
|
+
}
|
|
1640
|
+
if (legacyDrafts) for (const [locale, keys] of Object.entries(readDrafts(legacyDrafts))) markDrafts(state.drafts, locale, keys);
|
|
1625
1641
|
return state;
|
|
1626
1642
|
}
|
|
1643
|
+
function stateFile(cfg) {
|
|
1644
|
+
return [statePath(cfg), ...legacyPaths(cfg)].find((path) => existsSync(path));
|
|
1645
|
+
}
|
|
1646
|
+
function lockNews(cfg, before) {
|
|
1647
|
+
const lock = statePath(cfg);
|
|
1648
|
+
if (before === lock || !existsSync(lock)) return void 0;
|
|
1649
|
+
return before ? {
|
|
1650
|
+
file: lock,
|
|
1651
|
+
from: before
|
|
1652
|
+
} : { file: lock };
|
|
1653
|
+
}
|
|
1654
|
+
function checkVersion(path, version) {
|
|
1655
|
+
if (typeof version === "number" && version > LOCK_VERSION) throw new Error(`[verbaly] ${path} was written by a newer Verbaly (format ${version}): update @verbaly/compiler to read it`);
|
|
1656
|
+
}
|
|
1627
1657
|
function readState(cfg) {
|
|
1628
1658
|
try {
|
|
1629
1659
|
return { state: loadState(cfg) };
|
|
@@ -1640,21 +1670,23 @@ function readState(cfg) {
|
|
|
1640
1670
|
function saveState(cfg, state) {
|
|
1641
1671
|
const fresh = serializeState(state);
|
|
1642
1672
|
const path = statePath(cfg);
|
|
1643
|
-
const legacy =
|
|
1673
|
+
const legacy = legacyPaths(cfg);
|
|
1644
1674
|
if (fresh === void 0) {
|
|
1645
|
-
|
|
1646
|
-
rmSync(legacy, { force: true });
|
|
1675
|
+
for (const file of [path, ...legacy]) rmSync(file, { force: true });
|
|
1647
1676
|
return;
|
|
1648
1677
|
}
|
|
1649
|
-
|
|
1678
|
+
const existing = readText(path);
|
|
1679
|
+
if (existing === void 0) mkdirSync(cfg.root, { recursive: true });
|
|
1680
|
+
const serialized = withLineEndings(fresh, existing ?? legacy.map(readText).find((text) => text !== void 0));
|
|
1681
|
+
if (existing !== serialized) writeFileSync(path, serialized);
|
|
1682
|
+
for (const file of legacy) rmSync(file, { force: true });
|
|
1683
|
+
}
|
|
1684
|
+
function readText(path) {
|
|
1650
1685
|
try {
|
|
1651
|
-
|
|
1686
|
+
return readFileSync(path, "utf8");
|
|
1652
1687
|
} catch {
|
|
1653
|
-
|
|
1688
|
+
return;
|
|
1654
1689
|
}
|
|
1655
|
-
const serialized = withLineEndings(fresh, existing);
|
|
1656
|
-
if (existing !== serialized) writeFileSync(path, serialized);
|
|
1657
|
-
if (existsSync(legacy)) rmSync(legacy);
|
|
1658
1690
|
}
|
|
1659
1691
|
function updateState(cfg, catalogs) {
|
|
1660
1692
|
const next = refreshState(cfg, catalogs, loadState(cfg));
|
|
@@ -1802,25 +1834,27 @@ function serializeState(state) {
|
|
|
1802
1834
|
fingerprints[locale] = Object.fromEntries(keys.map((key) => [key, entries[key]]));
|
|
1803
1835
|
}
|
|
1804
1836
|
const migrated = [...new Set(state.migrated ?? [])].sort();
|
|
1805
|
-
|
|
1837
|
+
if (!Object.keys(drafts).length && !Object.keys(fingerprints).length && !migrated.length) return;
|
|
1838
|
+
const out = {
|
|
1839
|
+
_readme: README,
|
|
1840
|
+
version: LOCK_VERSION
|
|
1841
|
+
};
|
|
1806
1842
|
if (Object.keys(drafts).length) out.drafts = drafts;
|
|
1807
1843
|
if (Object.keys(fingerprints).length) out.fingerprints = fingerprints;
|
|
1808
1844
|
if (migrated.length) out.migrated = migrated;
|
|
1809
|
-
if (!out.drafts && !out.fingerprints && !out.migrated) return void 0;
|
|
1810
1845
|
return JSON.stringify(out, null, 2) + "\n";
|
|
1811
1846
|
}
|
|
1812
|
-
function
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
} catch {
|
|
1817
|
-
return;
|
|
1818
|
-
}
|
|
1847
|
+
function readObject(path) {
|
|
1848
|
+
const content = readText(path);
|
|
1849
|
+
if (content === void 0) return void 0;
|
|
1850
|
+
let value;
|
|
1819
1851
|
try {
|
|
1820
|
-
|
|
1852
|
+
value = JSON.parse(content.charCodeAt(0) === 65279 ? content.slice(1) : content);
|
|
1821
1853
|
} catch (error) {
|
|
1822
1854
|
throw corrupt(path, error);
|
|
1823
1855
|
}
|
|
1856
|
+
if (!isObject(value)) throw corrupt(path);
|
|
1857
|
+
return value;
|
|
1824
1858
|
}
|
|
1825
1859
|
function corrupt(path, cause) {
|
|
1826
1860
|
return new Error(`[verbaly] ${path} is not valid JSON: restore it from git or fix it (deleting it approves every draft)`, { cause });
|
|
@@ -2206,7 +2240,7 @@ async function init(input = {}) {
|
|
|
2206
2240
|
//#endregion
|
|
2207
2241
|
//#region src/check.ts
|
|
2208
2242
|
function gatePasses(result) {
|
|
2209
|
-
return result.missing.length === 0 && result.unknown.length === 0 && !result.broken.some((entry) => entry.severity === "error");
|
|
2243
|
+
return result.missing.length === 0 && result.unknown.length === 0 && result.collisions.length === 0 && !result.broken.some((entry) => entry.severity === "error");
|
|
2210
2244
|
}
|
|
2211
2245
|
function check(cfg, catalogs, registry, fingerprints = {}) {
|
|
2212
2246
|
const extracted = registry.messages();
|
|
@@ -2276,17 +2310,19 @@ function check(cfg, catalogs, registry, fingerprints = {}) {
|
|
|
2276
2310
|
});
|
|
2277
2311
|
}
|
|
2278
2312
|
}
|
|
2313
|
+
const collisions = collisionEntries(registry);
|
|
2279
2314
|
return {
|
|
2280
2315
|
ok: gatePasses({
|
|
2281
2316
|
missing,
|
|
2282
2317
|
unknown,
|
|
2283
|
-
broken
|
|
2318
|
+
broken,
|
|
2319
|
+
collisions
|
|
2284
2320
|
}),
|
|
2285
2321
|
missing,
|
|
2286
2322
|
unknown,
|
|
2287
2323
|
broken,
|
|
2288
2324
|
extra,
|
|
2289
|
-
collisions
|
|
2325
|
+
collisions,
|
|
2290
2326
|
divergent,
|
|
2291
2327
|
outdated: outdatedTranslations(cfg, shipped, fingerprints)
|
|
2292
2328
|
};
|
|
@@ -2310,6 +2346,10 @@ function formatCheckResult(result, root) {
|
|
|
2310
2346
|
lines.push("broken translations:");
|
|
2311
2347
|
for (const entry of errors) lines.push(` [${entry.locale}] ${entry.key}: ${entry.issue}`);
|
|
2312
2348
|
}
|
|
2349
|
+
if (result.collisions.length > 0) {
|
|
2350
|
+
lines.push("keys written with more than one text:");
|
|
2351
|
+
for (const entry of result.collisions) lines.push(` ${formatCollision(entry, root)}`);
|
|
2352
|
+
}
|
|
2313
2353
|
return lines.join("\n");
|
|
2314
2354
|
}
|
|
2315
2355
|
function checkNextSteps(result, cliReachable = true) {
|
|
@@ -2317,16 +2357,13 @@ function checkNextSteps(result, cliReachable = true) {
|
|
|
2317
2357
|
if (result.missing.length > 0) steps.push("missing: run `npx verbaly extract` to scaffold the keys, then fill them (or run `npx verbaly translate`)");
|
|
2318
2358
|
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`");
|
|
2319
2359
|
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");
|
|
2360
|
+
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");
|
|
2320
2361
|
if (steps.length > 0 && !cliReachable) steps.push(`the verbaly command is not linked in this project: ${CLI_INSTALL_FIX}`);
|
|
2321
2362
|
return steps.join("\n");
|
|
2322
2363
|
}
|
|
2323
2364
|
function formatCheckWarnings(result, root, options = {}) {
|
|
2324
2365
|
const lines = result.broken.filter((entry) => entry.severity === "warning").map((entry) => ` [${entry.locale}] ${entry.key}: ${entry.issue}`);
|
|
2325
2366
|
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`);
|
|
2326
|
-
for (const entry of result.collisions) lines.push(` ${formatFinding({
|
|
2327
|
-
kind: "collision",
|
|
2328
|
-
...entry
|
|
2329
|
-
}, root)}`);
|
|
2330
2367
|
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)`);
|
|
2331
2368
|
if (!options.outdatedFails) for (const entry of result.outdated) lines.push(` ${formatFinding({
|
|
2332
2369
|
kind: "outdated",
|
|
@@ -2378,7 +2415,7 @@ function githubCheckAnnotations(result, registry, cfg, options = {}) {
|
|
|
2378
2415
|
for (const { key, sites } of result.collisions) {
|
|
2379
2416
|
const texts = new Set(sites.map((place) => place.message)).size;
|
|
2380
2417
|
const text = escapeData(`"${key}" has ${counted(texts, "text")}, and every place shows the first one`);
|
|
2381
|
-
for (const place of sites) lines.push(`::
|
|
2418
|
+
for (const place of sites) lines.push(`::error ${at(place.file, place.line)}::${text}`);
|
|
2382
2419
|
}
|
|
2383
2420
|
for (const { key, code } of result.divergent) {
|
|
2384
2421
|
const text = escapeData(`"${key}": the source catalog has another text, the code's one ships`);
|
|
@@ -2940,7 +2977,7 @@ async function doctor(cfg) {
|
|
|
2940
2977
|
if (warnings.length > 0) warn("translations", `${counted(warnings.length, "structural warning")} (plural forms a language asks for)`, "run `npx verbaly check` to read them, they never fail the build");
|
|
2941
2978
|
if (result.collisions.length > 0) {
|
|
2942
2979
|
const first = result.collisions[0];
|
|
2943
|
-
|
|
2980
|
+
error("keys", `${counted(result.collisions.length, "key")} written with more than one text, and every place shows the first (${first.key}: ${first.sites.map((at) => sourcePlace(at, cfg.root)).join(", ")})`, "give each text its own key (`npx verbaly check` lists every place)");
|
|
2944
2981
|
}
|
|
2945
2982
|
if (result.divergent.length > 0) {
|
|
2946
2983
|
const first = result.divergent[0];
|
|
@@ -3774,11 +3811,17 @@ async function syncProject(cfg, options = {}) {
|
|
|
3774
3811
|
result.written[locale] = writeCatalog(cfg, locale, catalogs[locale] ?? {});
|
|
3775
3812
|
}
|
|
3776
3813
|
writeDts(cfg, catalogs[cfg.sourceLocale] ?? {});
|
|
3814
|
+
const before = stateFile(cfg);
|
|
3777
3815
|
try {
|
|
3778
3816
|
result.state = updateState(cfg, catalogs);
|
|
3779
3817
|
} catch (error) {
|
|
3780
3818
|
result.stateProblem = error.message.replace(/^\[verbaly\] /, "");
|
|
3781
3819
|
}
|
|
3820
|
+
const news = lockNews(cfg, before);
|
|
3821
|
+
if (news) result.findings.push({
|
|
3822
|
+
kind: "lock",
|
|
3823
|
+
...news
|
|
3824
|
+
});
|
|
3782
3825
|
return result;
|
|
3783
3826
|
}
|
|
3784
3827
|
function confirmFromDisk(cfg, catalogs, registry) {
|
|
@@ -4817,7 +4860,7 @@ async function runCli(args = process.argv.slice(2)) {
|
|
|
4817
4860
|
console.log(`[verbaly] ${counted(total, "message")} · locales: ${cfg.locales.join(", ")}${dryRun ? " (dry run, nothing written)" : ""}`);
|
|
4818
4861
|
for (const [locale, keys] of Object.entries(result.added)) console.log(` ${locale}: ${dryRun ? `would add ${keys.length}` : `+${keys.length}`}`);
|
|
4819
4862
|
const warnings = result.findings.filter((finding) => {
|
|
4820
|
-
if (finding.kind !== "replaced") return true;
|
|
4863
|
+
if (finding.kind !== "replaced" && finding.kind !== "lock") return true;
|
|
4821
4864
|
console.log(` ${formatFinding(finding, cfg.root)}`);
|
|
4822
4865
|
return false;
|
|
4823
4866
|
});
|
|
@@ -4846,6 +4889,7 @@ async function runCli(args = process.argv.slice(2)) {
|
|
|
4846
4889
|
return;
|
|
4847
4890
|
}
|
|
4848
4891
|
if (command === "migrate") {
|
|
4892
|
+
const lockBefore = stateFile(cfg);
|
|
4849
4893
|
const result = migrateCatalogs(cfg, {
|
|
4850
4894
|
write: values.write,
|
|
4851
4895
|
plurals: values.plurals
|
|
@@ -4868,6 +4912,7 @@ async function runCli(args = process.argv.slice(2)) {
|
|
|
4868
4912
|
for (const entry of result.skipped) console.log(` ${entry.locale} ${entry.key} ${entry.reason}`);
|
|
4869
4913
|
}
|
|
4870
4914
|
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`);
|
|
4915
|
+
sayLockNews(cfg, lockBefore);
|
|
4871
4916
|
if (values.write) console.log(" next: run verbaly check");
|
|
4872
4917
|
return;
|
|
4873
4918
|
}
|
|
@@ -4936,7 +4981,7 @@ async function runCli(args = process.argv.slice(2)) {
|
|
|
4936
4981
|
}
|
|
4937
4982
|
if (!result.ok) {
|
|
4938
4983
|
const brokenCount = result.broken.filter((entry) => entry.severity === "error").length;
|
|
4939
|
-
const report = reporter === "github" ? `[verbaly] check failed: ${result.missing.length} missing, ${result.unknown.length} unknown, ${brokenCount} broken` : `[verbaly] check failed\n${formatCheckResult(result, cfg.root)}`;
|
|
4984
|
+
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)}`;
|
|
4940
4985
|
console.error(`${report}\n${checkNextSteps(result)}`);
|
|
4941
4986
|
}
|
|
4942
4987
|
if (awaiting.length > 0) {
|
|
@@ -4985,7 +5030,9 @@ async function runCli(args = process.argv.slice(2)) {
|
|
|
4985
5030
|
const kept = keys.length - written.length;
|
|
4986
5031
|
if (kept > 0) console.log(` ${locale}: ${counted(kept, "message")} kept as written while this ran`);
|
|
4987
5032
|
}
|
|
5033
|
+
const lockBefore = stateFile(cfg);
|
|
4988
5034
|
if (writes.length > 0) recordTranslations(cfg, source, writes);
|
|
5035
|
+
sayLockNews(cfg, lockBefore);
|
|
4989
5036
|
for (const [locale, keys] of Object.entries(result.invalid)) console.warn(` ${locale}: ${keys.length} rejected (params/tags not preserved): ${keys.join(", ")}`);
|
|
4990
5037
|
for (const line of formatTranslateFailures(result.failed)) console.error(line);
|
|
4991
5038
|
if (result.failed.length > 0) process.exitCode = 1;
|
|
@@ -5015,7 +5062,9 @@ async function runCli(args = process.argv.slice(2)) {
|
|
|
5015
5062
|
}
|
|
5016
5063
|
acceptOutdated(cfg, shipped, state.fingerprints, outdated);
|
|
5017
5064
|
for (const [locale, keys] of byLocale(outdated)) console.log(` ${locale}: ${keys.length} kept for the new source text`);
|
|
5065
|
+
const lockBefore = stateFile(cfg);
|
|
5018
5066
|
saveState(cfg, state);
|
|
5067
|
+
sayLockNews(cfg, lockBefore);
|
|
5019
5068
|
const reviewed = new Set([...drafts, ...outdated].map(({ locale, key }) => `${locale}:${key}`));
|
|
5020
5069
|
console.log(`[verbaly] ${counted(reviewed.size, "translation")} marked reviewed ✓`);
|
|
5021
5070
|
return;
|
|
@@ -5119,7 +5168,9 @@ async function runCli(args = process.argv.slice(2)) {
|
|
|
5119
5168
|
const verb = values["dry-run"] ? "would import" : "imported";
|
|
5120
5169
|
console.log(` ${locale}: +${keys.length} ${verb}${values.draft ? " (draft)" : ""}`);
|
|
5121
5170
|
}
|
|
5171
|
+
const lockBefore = stateFile(cfg);
|
|
5122
5172
|
if (writes.length > 0) recordTranslations(cfg, catalogs[cfg.sourceLocale] ?? {}, writes);
|
|
5173
|
+
sayLockNews(cfg, lockBefore);
|
|
5123
5174
|
for (const [locale, keys] of Object.entries(result.skipped)) console.log(` ${locale}: ${keys.length} already translated, kept (use --overwrite to replace)`);
|
|
5124
5175
|
for (const [locale, keys] of Object.entries(result.rejected)) console.warn(` ${locale}: ${keys.length} rejected (params/tags not preserved): ${keys.join(", ")}`);
|
|
5125
5176
|
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(", ")}`);
|
|
@@ -5170,6 +5221,13 @@ function checkState(cfg, gating) {
|
|
|
5170
5221
|
if (problem) console.warn(`[verbaly] ${problem}, so outdated translations are not reported`);
|
|
5171
5222
|
return state;
|
|
5172
5223
|
}
|
|
5224
|
+
function sayLockNews(cfg, before) {
|
|
5225
|
+
const news = lockNews(cfg, before);
|
|
5226
|
+
if (news) console.log(` ${formatFinding({
|
|
5227
|
+
kind: "lock",
|
|
5228
|
+
...news
|
|
5229
|
+
}, cfg.root)}`);
|
|
5230
|
+
}
|
|
5173
5231
|
function byLocale(entries) {
|
|
5174
5232
|
const out = /* @__PURE__ */ new Map();
|
|
5175
5233
|
for (const { locale, key } of entries) {
|