fix(i18n): every language says one file and five files its own way

Finishes the plural work the previous wip commit started. t() picks a
count string's form by the language's own Intl.PluralRules, and every
locale now spells out the forms its language reaches with whole
numbers, about 160 count strings in all: one, few and many in Russian,
Ukrainian and Polish, one and few in Czech and Slovak, five forms in
Arabic, one in the others, none in Japanese, Korean, Chinese, Thai,
Vietnamese and Indonesian. Each language was translated and then
reviewed on its own. English no longer reads "1 files", "1 updates
available" or "photo(s)".

Count labels shown next to a number now take that number too: the
atlas and admin statistics, the trip cards, journey and shared trip
pills, packing templates, receipts, storage usage, the Studio export
note. A heading that shared its key with a counted label keeps a key of
its own (the boarding pass heading, the Bookings tab), so languages that
put a noun after a number in the singular keep a plural heading. The
plugin hosts chip passed its count through .replace() after t() and
never got a form; three toasts sent the count as text. Mail and push
texts for shared photos and suppressed storage failures pick their form
in code through pluralForm.

A whole number sent as text counts too, which is how in-app
notification params arrive, and the plural rule follows the language of
the strings on screen while another one still loads.

The parity check knows which forms each language needs and refuses
missing and impossible ones. It also reads keys that contain a colon
now: it skipped them, which hid 58 missing plugin permission texts in
Catalan and 35 in Vietnamese, both translated. The client parity test
covers every language of the registry instead of a hand-kept list of 19,
and the placeholder spec lets a form spell its number out only where
its category is that one number. Brazilian Portuguese error screens
were in Breton, and an Arabic dashboard label held Hebrew text.
This commit is contained in:
Maurice
2026-10-08 00:01:59 +00:00
parent 55697b75c1
commit bee500880e
851 changed files with 11378 additions and 6077 deletions
+8 -29
View File
@@ -29,15 +29,17 @@ import { readdirSync, readFileSync, statSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { getIntlLanguage } from '../src/i18n/languages.ts';
import { allPluralCategories, integerPluralCategories } from '../src/i18n/plural.ts';
import { allPluralCategories, integerPluralCategories, pluralFormOf, pluralGroups } from '../src/i18n/plural.ts';
const here = dirname(fileURLToPath(import.meta.url));
const i18nRoot = join(here, '..', 'src', 'i18n');
// 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
// exact pattern every domain file uses.
const TOP_LEVEL_KEY_RE = /^\s*'([a-z][a-zA-Z0-9.\-_]*)'\s*:/gm;
// exact pattern every domain file uses. Keys may hold a colon themselves
// (admin.plugins.perm.db:read:trips); without it in the class those keys were
// never compared, and two locales lacked dozens of them unnoticed.
const TOP_LEVEL_KEY_RE = /^\s*'([a-z][a-zA-Z0-9.\-_:]*)'\s*:/gm;
function listLocales() {
return readdirSync(i18nRoot)
@@ -61,31 +63,8 @@ function extractKeys(locale, file) {
return keys;
}
const VARIANT_CATEGORIES = ['zero', 'one', 'two', 'few', 'many'];
/** The plural groups en defines in one domain file: their base keys. */
function pluralGroups(enKeys) {
const groups = new Set();
for (const key of enKeys) {
const dot = key.lastIndexOf('.');
if (dot < 0 || !VARIANT_CATEGORIES.includes(key.slice(dot + 1))) continue;
const base = key.slice(0, dot);
if (enKeys.has(base) || enKeys.has(`${base}.other`)) groups.add(base);
}
return groups;
}
/** `{ base, category }` when `key` is a category form of one of `groups`. */
function asVariant(key, groups) {
const dot = key.lastIndexOf('.');
if (dot < 0) return null;
const category = key.slice(dot + 1);
const base = key.slice(0, dot);
return VARIANT_CATEGORIES.includes(category) && groups.has(base) ? { base, category } : null;
}
function withoutVariants(keys, groups) {
return new Set([...keys].filter((k) => !asVariant(k, groups)));
return new Set([...keys].filter((k) => !pluralFormOf(k, groups)));
}
/** What one locale owes the plural groups of one file. */
@@ -99,8 +78,8 @@ function checkPluralForms(locale, keys, groups) {
for (const c of required) if (!keys.has(`${base}.${c}`)) missing.push(`${base}.${c}`);
}
for (const key of keys) {
const v = asVariant(key, groups);
if (v && !allowed.has(v.category)) invalid.push(key);
const form = pluralFormOf(key, groups);
if (form && !allowed.has(form.category)) invalid.push(key);
}
return { missing, invalid };
}