Files
TREK/client/tests/unit/i18n/parity.test.ts
T
Maurice bee500880e 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.
2026-10-08 00:01:59 +00:00

49 lines
2.5 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { pluralFormOf, pluralGroups } from '@trek/shared'
import { SUPPORTED_LANGUAGE_CODES, type TranslationStrings } from '@trek/shared/i18n'
import en from '@trek/shared/i18n/en'
// Runtime guard for the aggregated i18n bundles. `t()` resolves keys against the
// active locale's flat dot-key map (see TranslationContext), so a key that is
// present in en but missing in another locale silently falls back to English at
// runtime — easy to ship, hard to notice. This test fails loudly when any locale
// drifts away from the en key set so translators get an explicit, diagnostic list.
//
// The shared package also runs a file-level parity check (shared/scripts), but
// that one only inspects per-domain source files; this one asserts the *merged*
// export each locale actually serves to the app. The locales come from the one
// registry, so a language added there is checked here without a second list.
const NON_EN_CODES = SUPPORTED_LANGUAGE_CODES.filter((code) => code !== 'en')
// A count-bearing string's category forms (`places.count.one`, `.few`, ...)
// differ by language on purpose: Russian needs `.few` and `.many`, Japanese
// none. They are left out of the key comparison here; the shared parity CLI
// checks each locale has exactly the forms its plural rule needs.
const groups = pluralGroups(Object.keys(en))
const isVariant = (k: string) => pluralFormOf(k, groups) !== null
const enKeys = new Set(Object.keys(en).filter((k) => !isVariant(k)))
describe('i18n locale key parity', () => {
it('covers every supported locale but en', () => {
expect(NON_EN_CODES.length).toBeGreaterThanOrEqual(26)
})
it.each(NON_EN_CODES)('%s has the exact same key set as en', async (locale) => {
const strings = ((await import(`@trek/shared/i18n/${locale}`)) as { default: TranslationStrings }).default
const localeKeys = new Set(Object.keys(strings).filter((k) => !isVariant(k)))
const missing = [...enKeys].filter((k) => !localeKeys.has(k))
const extra = [...localeKeys].filter((k) => !enKeys.has(k))
const diagnostic =
`Locale "${locale}" key drift vs en — ` +
`missing ${missing.length}` +
(missing.length ? ` (${missing.slice(0, 10).join(', ')}${missing.length > 10 ? ', …' : ''})` : '') +
`; extra ${extra.length}` +
(extra.length ? ` (${extra.slice(0, 10).join(', ')}${extra.length > 10 ? ', …' : ''})` : '')
expect(missing, diagnostic).toEqual([])
expect(extra, diagnostic).toEqual([])
})
})