The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
feat(i18n): untranslated strings per locale may only shrink
Maurice8f691bff5a41
diff --git a/shared/CLAUDE.md b/shared/CLAUDE.mdindex 05e60df91..3a33444d4 100644--- a/shared/CLAUDE.md+++ b/shared/CLAUDE.md@@ -11,7 +11,9 @@ npm run typecheck # tsc --noEmitnpm run lint # eslint --fix (rewrites files)npm run test # vitest run — co-located *.spec.ts filesnpm run i18n:parity # audit locale drift, exits 0-npm run i18n:parity:strict # CI gate — exits 1 on any drift+npm run i18n:parity:strict # CI gate, exits 1 on any drift (also runs the untranslated ratchet below)+npm run i18n:untranslated # the untranslated-strings ratchet on its own+npm run i18n:untranslated:update # lower scripts/i18n-untranslated-baseline.json after translating; never raises itnpm run contracts:open # CI gate (after build): open shapes in request schemas may only shrink```@@ -47,11 +49,11 @@ The parity rule governs **existing** routes; it is not a license to mint new deb- **`languages.ts`** — `SUPPORTED_LANGUAGES` is the canonical registry and the source of `SupportedLanguageCode`. Adding a language starts here.- **`<locale>/`** — one folder per language, one file per UI domain plus an `index.ts` barrel; each file exports a flat map of dot-namespaced keys typed as `TranslationStrings`. The runtime `t(key)` only resolves these top-level keys.- **`en/` is canonical.** Every other locale must have the identical file set and top-level keys — `i18n:parity:strict` enforces it in CI. When you add or rename a key, update every locale.-- **Every locale gets a real translation — an English placeholder is not acceptable.** Parity only checks that the key exists, so copying the `en` string passes CI while shipping English to those users. Write native phrasing with the locale's own punctuation and the same `{placeholders}` as `en`; if you genuinely cannot translate one, say so instead of filling it with English.+- **Every locale gets a real translation; an English placeholder is not acceptable.** Write native phrasing with the locale's own punctuation and the same `{placeholders}` as `en`; if you genuinely cannot translate one, say so instead of filling it with English. Parity only checks that the key exists, so `i18n:parity:strict` also runs a ratchet (`scripts/i18n-untranslated.mjs`): per locale and file, the `// en-fallback` markers and the unmarked values identical to `en` may not grow past `scripts/i18n-untranslated-baseline.json`. An identical value is excused only when, after dropping placeholders, markup, URLs/e-mail/paths and the multi-word names in `BRAND_NAMES`, at most one plain word is left (a word with a capital after its first letter, an acronym or a single letter does not count), so "{count} km", "GPX", "OAuth" and "Budget" pass and "Source code" does not. Deleting a marker without translating moves the string from one count to the other and still fails. After translating, run `npm run i18n:untranslated:update` to lower the baseline; nothing raises it.- **Count-bearing strings use plural forms, never `count === 1` in the caller.** The key holds the general form (the CLDR "other" category) and `key.zero|one|two|few|many` hold the forms the language's `Intl.PluralRules` selects for whole numbers (`plural.ts`); `t(key, { count })` (or `{ n }`) picks one. Pass the count as a number. Russian needs `.one`, `.few` and `.many`, Arabic all five, Japanese none. `i18n:parity` checks that every locale has exactly the forms its language reaches with whole numbers and none it never selects. A form may spell the number out (Arabic "ملف واحد") only where its category is that one number; French `one` also covers 0 and Russian `one` covers 21, so they keep `{count}`. A string whose wording changes with the number (the old "Copy to trip" for one place, "Copy {count} to trip" for more) is a plural group whose `one` drops the number where the language allows it, not two keys switched in the caller.- **An `en` string carrying `{count}` or `{n}` must be a plural group**, even when the forms read the same (a label such as "Notes: {count}"), so every language can inflect. `i18n:parity` refuses one that is not, unless `NOT_PLURAL` in `scripts/i18n-parity.mjs` lists it with a reason: only for a number that is never a quantity (a day number, a step, a multiplier). An entry that stops matching fails too.-- **Further i18n specs run in `npm test`** and fail changes that parity lets through: placeholder parity (every `{placeholder}` in an `en` string must appear in each translation), no `en` string may call TREK "self-hosted" (the same build runs on managed installs; exemptions live in the spec), and a wording regression test for plugin permission descriptions (currently one string; add a case there when a permission's real behavior changes). None of these are part of `i18n:parity`, which checks key sets, plural forms and count strings.-- **en holds every key the client names.** `npm run lint:i18n-keys` in `client/` resolves the keys `src/` passes to `t()` and its helpers against `en/`, read through `scripts/i18n-catalog.mjs`. That reader takes the tables as text: a value must be one string literal on the key's line or the next, and anything else (a concatenation, a template literal) is an error rather than a skipped key. Its spec uses the fixtures in `scripts/fixtures/`.+- **Further i18n specs run in `npm test`** and fail changes that parity lets through: placeholder parity (every `{placeholder}` in an `en` string must appear in each translation), no `en` string may call TREK "self-hosted" (the same build runs on managed installs; exemptions live in the spec), and a wording regression test for plugin permission descriptions (currently one string; add a case there when a permission's real behavior changes). None of these are part of `i18n:parity`, which checks key sets, plural forms, count strings and the untranslated ratchet.+- **The i18n scripts read the tables as text** through `scripts/i18n-catalog.mjs`: a value must be one string literal on the key's line or the next, and anything else (a concatenation, a template literal) is an error rather than a skipped key. Their specs use the fixtures in `scripts/fixtures/`. That en holds every key the client names is checked on the client side (`npm run lint:i18n-keys` in `client/`).## Sanitization (`src/sanitize/sanitize.ts`)diff --git a/shared/package.json b/shared/package.jsonindex 605c9fa70..804ada4be 100644--- a/shared/package.json+++ b/shared/package.json@@ -71,7 +71,9 @@"lint": "eslint --fix \"src/**/*.ts\"","i18n:parity": "node scripts/i18n-parity.mjs","i18n:parity:strict": "node scripts/i18n-parity.mjs --strict",- "contracts:open": "node scripts/open-request-schemas.mjs"+ "contracts:open": "node scripts/open-request-schemas.mjs",+ "i18n:untranslated": "node scripts/i18n-untranslated.mjs",+ "i18n:untranslated:update": "node scripts/i18n-untranslated.mjs --update"},"dependencies": {"isomorphic-dompurify": "^3.23.0",diff --git a/shared/scripts/fixtures/baseline-broken.json b/shared/scripts/fixtures/baseline-broken.jsonnew file mode 100644index 000000000..1bf8d526b--- /dev/null+++ b/shared/scripts/fixtures/baseline-broken.json@@ -0,0 +1 @@+{ "de": {diff --git a/shared/scripts/fixtures/baseline-shape.json b/shared/scripts/fixtures/baseline-shape.jsonnew file mode 100644index 000000000..ca7240e49--- /dev/null+++ b/shared/scripts/fixtures/baseline-shape.json@@ -0,0 +1 @@+{ "de": { "a.ts": { "marked": 1, "identical": "2" } } }diff --git a/shared/scripts/fixtures/i18n-missing/en/a.ts b/shared/scripts/fixtures/i18n-missing/en/a.tsnew file mode 100644index 000000000..83affa1e6--- /dev/null+++ b/shared/scripts/fixtures/i18n-missing/en/a.ts@@ -0,0 +1,14 @@+// Fixture for the i18n script specs: a canonical table.+const a = {+ 'a.title': 'Trip settings',+ 'a.count': '{count} places',+ 'a.count.one': '{count} place',+ 'a.lone': 'Remove {count} items',+ 'a.day': 'Day {n}',+ 'a.brand': 'Google Maps',+ 'a.code': 'GPX',+ 'a.quote': "It's here",+ 'a.multi':+ 'A long sentence that wraps onto the next line',+};+export default a;diff --git a/shared/scripts/fixtures/i18n-missing/fr/b.ts b/shared/scripts/fixtures/i18n-missing/fr/b.tsnew file mode 100644index 000000000..229b37da5--- /dev/null+++ b/shared/scripts/fixtures/i18n-missing/fr/b.ts@@ -0,0 +1,5 @@+// Fixture: a locale that lacks en's a.ts.+const b = {+ 'b.title': 'Titre',+};+export default b;diff --git a/shared/scripts/i18n-parity.mjs b/shared/scripts/i18n-parity.mjsindex 5c5d70a08..33411f80e 100644--- a/shared/scripts/i18n-parity.mjs+++ b/shared/scripts/i18n-parity.mjs@@ -23,6 +23,9 @@// `t()` picks a plural form by) must be a plural group, so every// language gets the forms it needs. The exceptions are NOT_PLURAL: a// number that is never a quantity ("Day {n}", a step, a multiplier).+// 5. Untranslated strings: the marked `// en-fallback` and unmarked English+// copies per locale and file may only shrink (i18n-untranslated.mjs,+// which also lowers the baseline with --update).//// Limitations: we only parse *top-level* string keys (those declared as the// first column of the file, matching the regex below). Nested objects, function@@ -34,6 +37,7 @@ import { join } from 'node:path';import { getIntlLanguage } from '../src/i18n/languages.ts';import { allPluralCategories, integerPluralCategories, pluralFormOf, pluralGroups } from '../src/i18n/plural.ts';import { I18N_ROOT, listDomainFiles, listLocales, readCatalog } from './i18n-catalog.mjs';+import { compare, countUntranslated, formatGrown, readBaseline } from './i18n-untranslated.mjs';// Match a top-level translation key declaration: leading whitespace, then a// quoted key (must start with a lowercase letter), then a colon. This is the@@ -115,6 +119,16 @@ function checkCountStrings(enFiles, notPlural = NOT_PLURAL, root = I18N_ROOT) {return { ungrouped, stale: [...allowed].filter((key) => !seen.has(key)) };}+/** The untranslated ratchet's verdict, with a reading error reported rather than thrown. */+function checkUntranslated() {+ try {+ const { grown, lowerable } = compare(countUntranslated(), readBaseline());+ return { error: null, grown, lowerable };+ } catch (err) {+ return { error: err.message, grown: [], lowerable: 0 };+ }+}+function diffSets(reference, candidate) {const missing = [];const extra = [];@@ -173,6 +187,7 @@ function checkParity() {}report.countDrift = checkCountStrings(enFiles);+ report.untranslated = checkUntranslated();return report;}@@ -226,6 +241,21 @@ function formatReport(report) {}}+ if (report.untranslated) {+ const { error, grown, lowerable } = report.untranslated;+ if (error) {+ lines.push(`Untranslated strings: cannot check, ${error}`);+ } else if (grown.length === 0) {+ lines.push(+ 'Untranslated strings: OK' ++ (lowerable ? ` (${lowerable} baseline entries can come down: node scripts/i18n-untranslated.mjs --update)` : ''),+ );+ } else {+ lines.push('Untranslated strings: grew past scripts/i18n-untranslated-baseline.json');+ lines.push(...formatGrown(grown));+ }+ }+return lines.join('\n');}@@ -239,13 +269,14 @@ if (isCli) {const strict = process.argv.includes('--strict');const filesOnly = process.argv.includes('--files-only');const report = checkParity();- const shown = filesOnly ? { ...report, keyDrift: [], pluralDrift: [], countDrift: null } : report;+ const shown = filesOnly ? { ...report, keyDrift: [], pluralDrift: [], countDrift: null, untranslated: null } : report;process.stdout.write(formatReport(shown) + '\n');if (strict) {const hasFileDrift = report.fileDrift.length > 0;const hasKeyDrift = filesOnly ? false : report.keyDrift.length > 0 || report.pluralDrift.length > 0;const hasCountDrift = !filesOnly && (report.countDrift.ungrouped.length > 0 || report.countDrift.stale.length > 0);- if (hasFileDrift || hasKeyDrift || hasCountDrift) process.exit(1);+ const hasUntranslated = !filesOnly && (report.untranslated.error !== null || report.untranslated.grown.length > 0);+ if (hasFileDrift || hasKeyDrift || hasCountDrift || hasUntranslated) process.exit(1);}}diff --git a/shared/scripts/i18n-untranslated-baseline.json b/shared/scripts/i18n-untranslated-baseline.jsonnew file mode 100644index 000000000..feee369a2--- /dev/null+++ b/shared/scripts/i18n-untranslated-baseline.json@@ -0,0 +1,276 @@+{+ "ar": {+ "admin.ts": { "marked": 22, "identical": 3 },+ "backup.ts": { "marked": 1, "identical": 0 },+ "collab.ts": { "marked": 1, "identical": 0 },+ "common.ts": { "marked": 13, "identical": 0 },+ "dayplan.ts": { "marked": 8, "identical": 0 },+ "journey.ts": { "marked": 284, "identical": 1 },+ "login.ts": { "marked": 1, "identical": 3 },+ "oauth.ts": { "marked": 19, "identical": 0 },+ "settings.ts": { "marked": 14, "identical": 39 },+ "system_notice.ts": { "marked": 3, "identical": 2 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "az": {+ "admin.ts": { "marked": 0, "identical": 2 },+ "journey.ts": { "marked": 0, "identical": 1 },+ "settings.ts": { "marked": 0, "identical": 1 }+ },+ "br": {+ "admin.ts": { "marked": 0, "identical": 13 },+ "common.ts": { "marked": 12, "identical": 0 },+ "dayplan.ts": { "marked": 2, "identical": 0 },+ "journey.ts": { "marked": 115, "identical": 0 },+ "login.ts": { "marked": 0, "identical": 3 },+ "oauth.ts": { "marked": 17, "identical": 0 },+ "settings.ts": { "marked": 0, "identical": 45 },+ "system_notice.ts": { "marked": 0, "identical": 4 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "ca": {+ "admin.ts": { "marked": 0, "identical": 4 },+ "journey.ts": { "marked": 110, "identical": 0 },+ "settings.ts": { "marked": 0, "identical": 9 },+ "system_notice.ts": { "marked": 0, "identical": 2 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "cs": {+ "admin.ts": { "marked": 0, "identical": 14 },+ "atlas.ts": { "marked": 0, "identical": 1 },+ "common.ts": { "marked": 12, "identical": 0 },+ "dayplan.ts": { "marked": 2, "identical": 0 },+ "journey.ts": { "marked": 115, "identical": 1 },+ "login.ts": { "marked": 0, "identical": 3 },+ "oauth.ts": { "marked": 17, "identical": 0 },+ "settings.ts": { "marked": 0, "identical": 44 },+ "system_notice.ts": { "marked": 0, "identical": 4 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "de": {+ "admin.ts": { "marked": 0, "identical": 12 },+ "journey.ts": { "marked": 9, "identical": 1 },+ "oauth.ts": { "marked": 17, "identical": 0 },+ "settings.ts": { "marked": 0, "identical": 11 },+ "system_notice.ts": { "marked": 0, "identical": 4 }+ },+ "es": {+ "admin.ts": { "marked": 0, "identical": 12 },+ "common.ts": { "marked": 12, "identical": 0 },+ "dayplan.ts": { "marked": 2, "identical": 0 },+ "journey.ts": { "marked": 115, "identical": 0 },+ "login.ts": { "marked": 0, "identical": 3 },+ "oauth.ts": { "marked": 17, "identical": 0 },+ "settings.ts": { "marked": 0, "identical": 45 },+ "system_notice.ts": { "marked": 0, "identical": 4 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "et": {+ "admin.ts": { "marked": 0, "identical": 1 },+ "settings.ts": { "marked": 0, "identical": 1 }+ },+ "fr": {+ "admin.ts": { "marked": 0, "identical": 14 },+ "atlas.ts": { "marked": 0, "identical": 1 },+ "common.ts": { "marked": 12, "identical": 0 },+ "dayplan.ts": { "marked": 2, "identical": 0 },+ "help.ts": { "marked": 0, "identical": 1 },+ "journey.ts": { "marked": 115, "identical": 1 },+ "login.ts": { "marked": 0, "identical": 3 },+ "notif.ts": { "marked": 0, "identical": 1 },+ "oauth.ts": { "marked": 17, "identical": 0 },+ "places.ts": { "marked": 0, "identical": 1 },+ "planner.ts": { "marked": 0, "identical": 1 },+ "roadtrip.ts": { "marked": 0, "identical": 2 },+ "settings.ts": { "marked": 0, "identical": 45 },+ "system_notice.ts": { "marked": 0, "identical": 4 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "gr": {+ "admin.ts": { "marked": 0, "identical": 4 },+ "common.ts": { "marked": 12, "identical": 0 },+ "dashboard.ts": { "marked": 36, "identical": 0 },+ "journey.ts": { "marked": 110, "identical": 1 },+ "login.ts": { "marked": 0, "identical": 3 },+ "oauth.ts": { "marked": 17, "identical": 0 },+ "settings.ts": { "marked": 0, "identical": 42 },+ "system_notice.ts": { "marked": 0, "identical": 2 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "hu": {+ "admin.ts": { "marked": 0, "identical": 15 },+ "common.ts": { "marked": 12, "identical": 0 },+ "dayplan.ts": { "marked": 2, "identical": 0 },+ "journey.ts": { "marked": 115, "identical": 0 },+ "login.ts": { "marked": 0, "identical": 3 },+ "oauth.ts": { "marked": 17, "identical": 0 },+ "settings.ts": { "marked": 0, "identical": 44 },+ "system_notice.ts": { "marked": 0, "identical": 4 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "id": {+ "admin.ts": { "marked": 0, "identical": 7 },+ "common.ts": { "marked": 12, "identical": 0 },+ "dayplan.ts": { "marked": 2, "identical": 0 },+ "journey.ts": { "marked": 115, "identical": 2 },+ "login.ts": { "marked": 0, "identical": 3 },+ "oauth.ts": { "marked": 17, "identical": 0 },+ "packing.ts": { "marked": 0, "identical": 1 },+ "settings.ts": { "marked": 0, "identical": 44 },+ "system_notice.ts": { "marked": 0, "identical": 4 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "it": {+ "admin.ts": { "marked": 0, "identical": 12 },+ "dayplan.ts": { "marked": 2, "identical": 0 },+ "journey.ts": { "marked": 115, "identical": 1 },+ "login.ts": { "marked": 0, "identical": 3 },+ "oauth.ts": { "marked": 17, "identical": 0 },+ "settings.ts": { "marked": 0, "identical": 45 },+ "storage.ts": { "marked": 0, "identical": 1 },+ "system_notice.ts": { "marked": 0, "identical": 4 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "ja": {+ "admin.ts": { "marked": 0, "identical": 2 },+ "common.ts": { "marked": 12, "identical": 0 },+ "journey.ts": { "marked": 110, "identical": 1 },+ "login.ts": { "marked": 0, "identical": 3 },+ "oauth.ts": { "marked": 17, "identical": 0 },+ "settings.ts": { "marked": 0, "identical": 41 },+ "system_notice.ts": { "marked": 0, "identical": 2 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "ko": {+ "admin.ts": { "marked": 0, "identical": 2 },+ "common.ts": { "marked": 12, "identical": 0 },+ "journey.ts": { "marked": 110, "identical": 0 },+ "login.ts": { "marked": 0, "identical": 3 },+ "oauth.ts": { "marked": 17, "identical": 0 },+ "settings.ts": { "marked": 0, "identical": 39 },+ "system_notice.ts": { "marked": 0, "identical": 2 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "nl": {+ "admin.ts": { "marked": 0, "identical": 3 },+ "common.ts": { "marked": 12, "identical": 0 },+ "dayplan.ts": { "marked": 2, "identical": 0 },+ "journey.ts": { "marked": 115, "identical": 1 },+ "login.ts": { "marked": 0, "identical": 3 },+ "oauth.ts": { "marked": 17, "identical": 0 },+ "places.ts": { "marked": 0, "identical": 1 },+ "settings.ts": { "marked": 0, "identical": 48 },+ "system_notice.ts": { "marked": 0, "identical": 5 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "pl": {+ "admin.ts": { "marked": 0, "identical": 14 },+ "common.ts": { "marked": 12, "identical": 0 },+ "dayplan.ts": { "marked": 2, "identical": 0 },+ "journey.ts": { "marked": 115, "identical": 1 },+ "login.ts": { "marked": 0, "identical": 3 },+ "oauth.ts": { "marked": 17, "identical": 0 },+ "settings.ts": { "marked": 0, "identical": 44 },+ "system_notice.ts": { "marked": 0, "identical": 4 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "ru": {+ "admin.ts": { "marked": 0, "identical": 13 },+ "common.ts": { "marked": 12, "identical": 0 },+ "dayplan.ts": { "marked": 2, "identical": 0 },+ "journey.ts": { "marked": 115, "identical": 0 },+ "login.ts": { "marked": 0, "identical": 3 },+ "oauth.ts": { "marked": 17, "identical": 0 },+ "settings.ts": { "marked": 0, "identical": 10 },+ "system_notice.ts": { "marked": 0, "identical": 4 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "sk": {+ "admin.ts": { "marked": 0, "identical": 4 },+ "atlas.ts": { "marked": 0, "identical": 1 },+ "journey.ts": { "marked": 0, "identical": 1 },+ "settings.ts": { "marked": 0, "identical": 5 },+ "system_notice.ts": { "marked": 0, "identical": 2 }+ },+ "sv": {+ "admin.ts": { "marked": 0, "identical": 8 },+ "budget.ts": { "marked": 0, "identical": 4 },+ "journey.ts": { "marked": 110, "identical": 0 },+ "login.ts": { "marked": 0, "identical": 3 },+ "packing.ts": { "marked": 0, "identical": 1 },+ "roadtrip.ts": { "marked": 0, "identical": 1 },+ "settings.ts": { "marked": 0, "identical": 38 },+ "system_notice.ts": { "marked": 0, "identical": 2 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "th": {+ "admin.ts": { "marked": 0, "identical": 1 }+ },+ "tr": {+ "admin.ts": { "marked": 0, "identical": 4 },+ "collab.ts": { "marked": 0, "identical": 1 },+ "common.ts": { "marked": 12, "identical": 0 },+ "journey.ts": { "marked": 110, "identical": 2 },+ "login.ts": { "marked": 0, "identical": 6 },+ "memories.ts": { "marked": 0, "identical": 1 },+ "notifications.ts": { "marked": 0, "identical": 1 },+ "oauth.ts": { "marked": 17, "identical": 0 },+ "settings.ts": { "marked": 0, "identical": 40 },+ "system_notice.ts": { "marked": 0, "identical": 3 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 3 }+ },+ "uk": {+ "admin.ts": { "marked": 0, "identical": 4 },+ "common.ts": { "marked": 12, "identical": 0 },+ "journey.ts": { "marked": 110, "identical": 0 },+ "login.ts": { "marked": 0, "identical": 3 },+ "oauth.ts": { "marked": 17, "identical": 0 },+ "settings.ts": { "marked": 0, "identical": 44 },+ "system_notice.ts": { "marked": 0, "identical": 4 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "vi": {+ "admin.ts": { "marked": 0, "identical": 4 },+ "journey.ts": { "marked": 110, "identical": 0 },+ "settings.ts": { "marked": 0, "identical": 3 },+ "system_notice.ts": { "marked": 0, "identical": 1 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "zh": {+ "admin.ts": { "marked": 0, "identical": 2 },+ "journey.ts": { "marked": 110, "identical": 0 },+ "settings.ts": { "marked": 0, "identical": 8 },+ "system_notice.ts": { "marked": 0, "identical": 2 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ },+ "zh-TW": {+ "admin.ts": { "marked": 0, "identical": 11 },+ "common.ts": { "marked": 12, "identical": 0 },+ "dayplan.ts": { "marked": 2, "identical": 0 },+ "journey.ts": { "marked": 115, "identical": 0 },+ "login.ts": { "marked": 0, "identical": 3 },+ "oauth.ts": { "marked": 17, "identical": 0 },+ "settings.ts": { "marked": 0, "identical": 44 },+ "system_notice.ts": { "marked": 0, "identical": 4 },+ "undo.ts": { "marked": 0, "identical": 1 },+ "vacay.ts": { "marked": 0, "identical": 5 }+ }+}diff --git a/shared/scripts/i18n-untranslated.mjs b/shared/scripts/i18n-untranslated.mjsnew file mode 100644index 000000000..020426ca2--- /dev/null+++ b/shared/scripts/i18n-untranslated.mjs@@ -0,0 +1,220 @@+#!/usr/bin/env node+/**+ * i18n:untranslated: English left in the other locales may only shrink.+ *+ * Parity proves every locale has every key, not that the key holds the+ * locale's own language: a copied en string passes it. Two kinds of copy are+ * counted per locale and domain file:+ *+ * marked a declaration carrying `// en-fallback`, the marker a+ * translator leaves on a string they could not translate yet+ * identical an unmarked value equal to en's, unless the rule in+ * `isInvariant` says the text reads the same in every language+ *+ * Both counts are held at scripts/i18n-untranslated-baseline.json. The check+ * fails when either grows past its entry (a file without one may hold none),+ * so a feature can no longer ship 26 English copies of a new string. Lowering+ * is a separate, explicit step:+ *+ * node scripts/i18n-untranslated.mjs check against the baseline (CI, via i18n-parity --strict)+ * node scripts/i18n-untranslated.mjs --update lower the baseline to today's counts; it never raises an+ * entry and drops the ones that reach zero+ *+ * The two counts are separate on purpose: deleting a marker without+ * translating the string moves it from `marked` to `identical`, and the+ * identical count refuses it.+ *+ * Fails closed: a missing or malformed baseline, a locale lacking one of en's+ * files, or a value the catalogue reader cannot parse is an error, never a+ * pass.+ */+import { existsSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';+import { dirname, join } from 'node:path';+import { fileURLToPath } from 'node:url';+import { asPath, I18N_ROOT, listDomainFiles, listLocales, readCatalog } from './i18n-catalog.mjs';++export const BASELINE = join(dirname(fileURLToPath(import.meta.url)), 'i18n-untranslated-baseline.json');++/**+ * Names of two or more plain words that read the same in every language.+ * One-word names (Mapbox, Immich) and names with an inner capital (MapLibre,+ * OpenStreetMap) are already covered by the word rule below.+ */+export const BRAND_NAMES = ['Apple Maps', 'Google Maps', 'Google Places', 'Home Assistant', 'Organic Maps', 'Synology Photos'];++const PLACEHOLDER_RE = /\{[a-zA-Z0-9_]+\}/g;+const TAG_RE = /<\/?[a-zA-Z][^>]*>/g;+// A URL, an e-mail address or a path: anything with a slash or an at sign in it.+const ADDRESS_RE = /\S*[/@]\S*/g;+// Hyphens join a word: "Check-in", "Wi-Fi" and "Auto-Backup" are one each.+const WORD_RE = /\p{L}[\p{L}\p{M}'’-]*/gu;++/**+ * A word in the sense of the rule: two letters or more and no capital after+ * the first. Single letters (the A and Z of a sort label, the v of+ * "v{version}"), acronyms (GPX, URLs, 2FA) and names with an inner capital+ * (OAuth, AirTrail) are not words here.+ */+export const isPlainWord = (word) => word.length >= 2 && !/\p{Lu}/u.test(word.slice(1));++/**+ * Whether a value equal to en's is legitimately the same text. True when,+ * after dropping placeholders, markup, addresses and the brand names above,+ * at most one plain word is left: "{count} km", "OAuth", "GPX", "Google Maps",+ * "PDF · {size}", "Budget", the sort label "Name (A to Z)". Two plain words or+ * more are a phrase, and phrases differ between languages.+ */+export function isInvariant(value) {+ let text = value.replace(PLACEHOLDER_RE, ' ').replace(TAG_RE, ' ').replace(ADDRESS_RE, ' ');+ for (const name of BRAND_NAMES) text = text.split(name).join(' ');+ return (text.match(WORD_RE) ?? []).filter(isPlainWord).length <= 1;+}++/**+ * Today's counts: `{ [locale]: { [file]: { marked, identical } } }`, only+ * non-zero entries. Throws on a locale missing one of en's files or a value+ * the reader cannot parse.+ */+export function countUntranslated(root = I18N_ROOT) {+ const locales = listLocales(root);+ if (!locales.includes('en')) throw new Error(`${asPath(root)}/en is required as the reference locale`);+ const enFiles = listDomainFiles('en', root);+ const enValues = new Map(enFiles.map((f) => [f, new Map(readCatalog('en', f, root).map((e) => [e.key, e.value]))]));+ const counts = {};+ for (const locale of locales) {+ if (locale === 'en') continue;+ const files = new Set(listDomainFiles(locale, root));+ for (const file of enFiles) {+ if (!files.has(file)) throw new Error(`${locale}/${file} is missing; run i18n-parity for the file report`);+ const en = enValues.get(file);+ let marked = 0;+ let identical = 0;+ for (const { key, value, marked: isMarked } of readCatalog(locale, file, root)) {+ if (isMarked) marked++;+ else if (en.get(key) === value && !isInvariant(value)) identical++;+ }+ if (marked || identical) (counts[locale] ??= {})[file] = { marked, identical };+ }+ }+ return counts;+}++/** The committed baseline. Throws when it is missing or not the expected shape. */+export function readBaseline(path = BASELINE) {+ let parsed;+ try {+ parsed = JSON.parse(readFileSync(path, 'utf8'));+ } catch (err) {+ throw new Error(`${path} cannot be read: ${err.message}. Restore it from git before running the check again.`);+ }+ const isCount = (n) => Number.isInteger(n) && n >= 0;+ const valid =+ parsed !== null &&+ typeof parsed === 'object' &&+ !Array.isArray(parsed) &&+ Object.values(parsed).every(+ (files) =>+ files !== null &&+ typeof files === 'object' &&+ Object.values(files).every(+ (entry) => entry !== null && typeof entry === 'object' && isCount(entry.marked) && isCount(entry.identical),+ ),+ );+ if (!valid) throw new Error(`${path} is not a { locale: { file: { marked, identical } } } map of whole numbers`);+ return parsed;+}++const ZERO = { marked: 0, identical: 0 };++/** Every count above its baseline entry, and how many entries could come down. */+export function compare(counts, baseline) {+ const grown = [];+ let lowerable = 0;+ for (const [locale, files] of Object.entries(counts)) {+ for (const [file, now] of Object.entries(files)) {+ const allowed = baseline[locale]?.[file] ?? ZERO;+ for (const kind of ['marked', 'identical']) {+ if (now[kind] > allowed[kind]) grown.push({ locale, file, kind, now: now[kind], allowed: allowed[kind] });+ }+ }+ }+ for (const [locale, files] of Object.entries(baseline)) {+ for (const [file, allowed] of Object.entries(files)) {+ const now = counts[locale]?.[file] ?? ZERO;+ if (now.marked < allowed.marked || now.identical < allowed.identical) lowerable++;+ }+ }+ return { grown, lowerable };+}++/** The baseline lowered to `counts`: never raised, zero entries dropped, sorted. */+export function lowered(counts, baseline) {+ const out = {};+ for (const locale of Object.keys(baseline).sort()) {+ for (const file of Object.keys(baseline[locale]).sort()) {+ const allowed = baseline[locale][file];+ const now = counts[locale]?.[file] ?? ZERO;+ const entry = {+ marked: Math.min(allowed.marked, now.marked),+ identical: Math.min(allowed.identical, now.identical),+ };+ if (entry.marked || entry.identical) (out[locale] ??= {})[file] = entry;+ }+ }+ return out;+}++/** The baseline as committed: one line per file, so a diff shows which counts came down. */+export function serialize(baseline) {+ const locales = Object.keys(baseline).map((locale) => {+ const files = Object.entries(baseline[locale]).map(+ ([file, { marked, identical }]) =>+ ` ${JSON.stringify(file)}: { "marked": ${marked}, "identical": ${identical} }`,+ );+ return ` ${JSON.stringify(locale)}: {\n${files.join(',\n')}\n }`;+ });+ return `{\n${locales.join(',\n')}\n}\n`;+}++export function formatGrown(grown) {+ return grown.map(+ ({ locale, file, kind, now, allowed }) =>+ ` ${locale}/${file}: ${now} ${kind === 'marked' ? 'marked en-fallback' : 'unmarked English copies'}, ` ++ `the baseline allows ${allowed}`,+ );+}++const total = (map, kind) =>+ Object.values(map)+ .flatMap((files) => Object.values(files))+ .reduce((sum, e) => sum + e[kind], 0);++// Compared by real path, so the check still runs when the script is started through a symlink.+const isCli =+ Boolean(process.argv[1]) && existsSync(process.argv[1]) && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url);+if (isCli) {+ try {+ const counts = countUntranslated();+ let baseline = readBaseline();+ if (process.argv.includes('--update')) {+ baseline = lowered(counts, baseline);+ writeFileSync(BASELINE, serialize(baseline));+ }+ const { grown, lowerable } = compare(counts, baseline);+ if (grown.length) {+ console.error('Untranslated strings grew past scripts/i18n-untranslated-baseline.json:');+ for (const line of formatGrown(grown)) console.error(line);+ console.error('Translate the new strings (shared/CLAUDE.md: an English placeholder is not acceptable).');+ }+ if (lowerable && !process.argv.includes('--update')) {+ console.log(`${lowerable} baseline entr${lowerable === 1 ? 'y is' : 'ies are'} above today's count: run with --update to lower.`);+ }+ console.log(+ `untranslated: ${total(counts, 'marked')} marked en-fallback, ${total(counts, 'identical')} unmarked English copies`,+ );+ if (grown.length) process.exit(1);+ } catch (err) {+ console.error(`FAIL ${err.message}`);+ process.exit(1);+ }+}diff --git a/shared/src/i18n/i18n-parity.spec.ts b/shared/src/i18n/i18n-parity.spec.tsindex 8c3b71631..20f48eea6 100644--- a/shared/src/i18n/i18n-parity.spec.ts+++ b/shared/src/i18n/i18n-parity.spec.ts@@ -62,5 +62,7 @@ describe('i18n count strings', () => {it('every count-bearing en string is a plural group or on NOT_PLURAL', () => {const report = checkParity();expect(report.countDrift).toEqual({ ungrouped: [], stale: [] });+ expect(report.untranslated.error).toBeNull();+ expect(report.untranslated.grown).toEqual([]);});});diff --git a/shared/src/i18n/i18n-untranslated.spec.ts b/shared/src/i18n/i18n-untranslated.spec.tsnew file mode 100644index 000000000..bb295a48d--- /dev/null+++ b/shared/src/i18n/i18n-untranslated.spec.ts@@ -0,0 +1,102 @@+import {+ compare,+ countUntranslated,+ isInvariant,+ lowered,+ readBaseline,+ serialize,+ // @ts-expect-error: plain .mjs script with no .d.ts; import as JS module.+} from '../../scripts/i18n-untranslated.mjs';++import { describe, it, expect } from 'vitest';++/**+ * The untranslated-strings ratchet (scripts/i18n-untranslated.mjs). The+ * fixtures under scripts/fixtures/ hold a two-locale table with one marked+ * fallback, two unmarked English copies and the invariant strings the rule+ * excuses.+ */+const FIXTURES = new URL('../../scripts/fixtures/', import.meta.url);+const ROOT = new URL('i18n/', FIXTURES);++type Counts = Record<string, Record<string, { marked: number; identical: number }>>;++describe('i18n untranslated ratchet', () => {+ it('excuses placeholders, codes, names and single words, never a phrase', () => {+ for (const same of [+ '{count} km',+ 'GPX',+ 'OAuth',+ 'Google Maps',+ 'PDF · {size}',+ 'Budget',+ 'Name (A\u2013Z)',+ 'Check-in',+ 'https://ntfy.sh',+ '[email protected]',+ 'Update → v{version}',+ '<b>{name}</b>',+ ]) {+ expect([same, isInvariant(same)]).toEqual([same, true]);+ }+ for (const copy of [+ 'Trip settings',+ 'Remove {count} items',+ 'Open in Google Maps',+ 'Source code',+ 'Made with TREK',+ ]) {+ expect([copy, isInvariant(copy)]).toEqual([copy, false]);+ }+ });++ it('counts marked fallbacks and unmarked English copies per locale and file', () => {+ expect(countUntranslated(ROOT)).toEqual({ de: { 'a.ts': { marked: 1, identical: 2 } } });+ });++ it('fails when a count grows past its entry and when a file without one has any', () => {+ const counts: Counts = { de: { 'a.ts': { marked: 1, identical: 3 } }, fr: { 'b.ts': { marked: 1, identical: 0 } } };+ const baseline: Counts = { de: { 'a.ts': { marked: 2, identical: 2 } } };+ const { grown, lowerable } = compare(counts, baseline);+ expect(grown).toEqual([+ { locale: 'de', file: 'a.ts', kind: 'identical', now: 3, allowed: 2 },+ { locale: 'fr', file: 'b.ts', kind: 'marked', now: 1, allowed: 0 },+ ]);+ expect(lowerable).toBe(1);+ });++ it('refuses a marker deleted without translating the string', () => {+ const before: Counts = { de: { 'a.ts': { marked: 1, identical: 2 } } };+ const markerDropped: Counts = { de: { 'a.ts': { marked: 0, identical: 3 } } };+ expect(compare(markerDropped, before).grown).toHaveLength(1);+ });++ it('only ever lowers the baseline on --update and drops entries that reach zero', () => {+ const baseline: Counts = {+ de: { 'a.ts': { marked: 2, identical: 2 }, 'b.ts': { marked: 1, identical: 0 } },+ };+ const counts: Counts = { de: { 'a.ts': { marked: 3, identical: 1 } } };+ expect(lowered(counts, baseline)).toEqual({ de: { 'a.ts': { marked: 2, identical: 1 } } });+ });++ it('writes one line per file and reads back what it wrote', () => {+ const baseline: Counts = { de: { 'a.ts': { marked: 2, identical: 1 } } };+ const text = serialize(baseline);+ expect(text).toBe('{\n "de": {\n "a.ts": { "marked": 2, "identical": 1 }\n }\n}\n');+ expect(JSON.parse(text)).toEqual(baseline);+ });++ it('fails closed on a missing, unparsable or misshapen baseline', () => {+ expect(() => readBaseline(new URL('missing.json', FIXTURES))).toThrow(/cannot be read/);+ expect(() => readBaseline(new URL('baseline-broken.json', FIXTURES))).toThrow(/cannot be read/);+ expect(() => readBaseline(new URL('baseline-shape.json', FIXTURES))).toThrow(/whole numbers/);+ });++ it('fails closed on a locale that lacks one of en’s files', () => {+ expect(() => countUntranslated(new URL('i18n-missing/', FIXTURES))).toThrow(/fr\/a\.ts is missing/);+ });++ it('holds the real locales at the committed baseline', () => {+ expect(compare(countUntranslated(), readBaseline()).grown).toEqual([]);+ });+});