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
@@ -1,4 +1,4 @@
// FE-COMP-I18NCTX-001 to FE-COMP-I18NCTX-017 (plus -003b / -013b)
// FE-COMP-I18NCTX-001 to FE-COMP-I18NCTX-018 (plus -003b / -013b)
import { act, render, screen, waitFor } from '@testing-library/react';
import { SUPPORTED_LANGUAGES, TranslationProvider, useTranslation } from '../../../src/i18n/TranslationContext';
import { TransHtml } from '../../../src/i18n/TransHtml';
@@ -140,6 +140,16 @@ describe('TranslationProvider', () => {
}
});
it('FE-COMP-I18NCTX-018: plural forms follow the language of the strings on screen, not the one still loading', async () => {
withLanguage('ru');
render(<TranslationProvider><Probe tKey="places.count" params={{ count: 21 }} /></TranslationProvider>);
// English strings until the Russian chunk arrives, read with the English
// rule: 21 is "other" there, while Russian's rule would pick English's .one.
expect(screen.getByTestId('value').textContent).toBe('21 places');
await waitFor(() => expect(screen.getByTestId('value').textContent).toBe('21 место'));
});
it('FE-COMP-I18NCTX-012: the default context outside a provider echoes the key', () => {
render(<Probe tKey="common.save" />);
expect(screen.getByTestId('value').textContent).toBe('common.save');
+24 -54
View File
@@ -1,25 +1,7 @@
import { describe, it, expect } from 'vitest'
import type { TranslationStrings } from '@trek/shared/i18n'
import { pluralFormOf, pluralGroups } from '@trek/shared'
import { SUPPORTED_LANGUAGE_CODES, type TranslationStrings } from '@trek/shared/i18n'
import en from '@trek/shared/i18n/en'
import de from '@trek/shared/i18n/de'
import es from '@trek/shared/i18n/es'
import fr from '@trek/shared/i18n/fr'
import hu from '@trek/shared/i18n/hu'
import itIT from '@trek/shared/i18n/it'
import tr from '@trek/shared/i18n/tr'
import ru from '@trek/shared/i18n/ru'
import zh from '@trek/shared/i18n/zh'
import zhTW from '@trek/shared/i18n/zh-TW'
import nl from '@trek/shared/i18n/nl'
import idID from '@trek/shared/i18n/id'
import ar from '@trek/shared/i18n/ar'
import br from '@trek/shared/i18n/br'
import cs from '@trek/shared/i18n/cs'
import pl from '@trek/shared/i18n/pl'
import ja from '@trek/shared/i18n/ja'
import ko from '@trek/shared/i18n/ko'
import uk from '@trek/shared/i18n/uk'
import gr from '@trek/shared/i18n/gr'
// 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
@@ -29,50 +11,38 @@ import gr from '@trek/shared/i18n/gr'
//
// 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.
// 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_LOCALES: Record<string, TranslationStrings> = {
de, es, fr, hu, it: itIT, tr, ru, zh, 'zh-TW': zhTW, nl, id: idID,
ar, br, cs, pl, ja, ko, uk, gr,
}
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 VARIANTS = ['zero', 'one', 'two', 'few', 'many']
const allEnKeys = new Set(Object.keys(en))
const pluralGroups = new Set(
[...allEnKeys]
.filter((k) => VARIANTS.includes(k.slice(k.lastIndexOf('.') + 1)))
.map((k) => k.slice(0, k.lastIndexOf('.')))
.filter((base) => allEnKeys.has(base) || allEnKeys.has(`${base}.other`)),
)
const isVariant = (k: string) =>
VARIANTS.includes(k.slice(k.lastIndexOf('.') + 1)) && pluralGroups.has(k.slice(0, k.lastIndexOf('.')))
const enKeys = new Set([...allEnKeys].filter((k) => !isVariant(k)))
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 non-en locale', () => {
// Keep the assertion set in lockstep with the supported language list minus en.
expect(Object.keys(NON_EN_LOCALES)).toHaveLength(19)
it('covers every supported locale but en', () => {
expect(NON_EN_CODES.length).toBeGreaterThanOrEqual(26)
})
for (const [locale, strings] of Object.entries(NON_EN_LOCALES)) {
it(`${locale} has the exact same key set as en`, () => {
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))
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 ? ', …' : ''})` : '')
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([])
})
}
expect(missing, diagnostic).toEqual([])
expect(extra, diagnostic).toEqual([])
})
})
@@ -69,7 +69,7 @@ describe('MAdminPackingTemplateManager', () => {
await screen.findByText('Beach Trip');
expect(screen.getByText('City Break')).toBeInTheDocument();
expect(screen.getByText('2 categories · 5 items')).toBeInTheDocument();
expect(screen.getByText('1 categories · 3 items')).toBeInTheDocument();
expect(screen.getByText('1 category · 3 items')).toBeInTheDocument();
});
it('FE-MOB-APKG-003: a failing list request surfaces the load error toast', async () => {
@@ -301,7 +301,7 @@ describe('MAdminPluginsPanel — toolbar', () => {
[registryEntry({ id: 'zulu', name: 'Zulu', latest: '2.0.0' }), registryEntry({ id: 'alpha', name: 'Alpha', latest: '1.0.0' })],
);
render(<MAdminPluginsPanel />);
await screen.findByText('1 updates available for your plugins.');
await screen.findByText('1 update available for your plugins.');
fireEvent.click(screen.getByTitle('Sort: Name'));
fireEvent.click(await screen.findByRole('button', { name: 'Updates first' }));
@@ -318,7 +318,7 @@ describe('MAdminPluginsPanel — toolbar', () => {
[registryEntry({ id: 'alpha', name: 'Alpha', latest: '2.0.0' }), registryEntry({ id: 'zulu', name: 'Zulu', latest: '9.0.0' })],
);
render(<MAdminPluginsPanel />);
await screen.findByText('1 updates available for your plugins.');
await screen.findByText('1 update available for your plugins.');
fireEvent.click(screen.getByTitle('Status: All'));
fireEvent.click(await screen.findByRole('button', { name: 'Update available' }));
@@ -932,7 +932,7 @@ describe('MAdminPluginsPanel — updates and consent', () => {
);
render(<MAdminPluginsPanel />);
expect(await screen.findByText('1 updates available for your plugins.')).toBeInTheDocument();
expect(await screen.findByText('1 update available for your plugins.')).toBeInTheDocument();
expect(screen.getByRole('button', { name: /update → v2\.0\.0/i })).toBeInTheDocument();
});
@@ -74,7 +74,7 @@ describe('MAdminUsersSection', () => {
it('FE-MOB-AUSERS-001: lists users with role badges, the "you" marker and the count', () => {
renderSection({ users: [ME, ALICE], currentUser: ME });
expect(screen.getByText('2 users')).toBeInTheDocument();
expect(screen.getByText('2 Users')).toBeInTheDocument();
expect(screen.getByText('admin')).toBeInTheDocument();
expect(screen.getByText('alice@example.com')).toBeInTheDocument();
expect(screen.getByText('Administrator')).toBeInTheDocument();
@@ -133,8 +133,8 @@ describe('MAtlas', () => {
render(<MAtlas />);
expect(await screen.findByText('Japan')).toBeInTheDocument();
expect(screen.getAllByText((_, el) => el?.textContent?.trim() === '2 atlas.places').length).toBeGreaterThan(0);
expect(screen.getAllByText((_, el) => el?.textContent?.trim() === '2 atlas.trips').length).toBeGreaterThan(0);
expect(screen.getAllByText((_, el) => el?.textContent?.trim() === '2 atlas.places:2').length).toBeGreaterThan(0);
expect(screen.getAllByText((_, el) => el?.textContent?.trim() === '2 atlas.trips:2').length).toBeGreaterThan(0);
expect(screen.getByText('Kansai')).toBeInTheDocument();
});
@@ -114,7 +114,7 @@ describe('MCollTripPickerSheet', () => {
fireEvent.click(await screen.findByRole('button', { name: /Japan 2020/ }))
await waitFor(() => expect(onClose).toHaveBeenCalled())
expect(onCopy).toHaveBeenCalledWith(1)
expect(addToast).toHaveBeenCalledWith('Copied 1 places', 'success', undefined)
expect(addToast).toHaveBeenCalledWith('Copied 1 place', 'success', undefined)
})
it('FE-MOB-CTRIPP-010: duplicates the server skipped get their own toast', async () => {
@@ -122,7 +122,7 @@ describe('MCollTripPickerSheet', () => {
.mockResolvedValue({ copied: 2, skipped: [{ id: 9, name: 'Louvre' }] })
setup({ onCopy })
fireEvent.click(await screen.findByRole('button', { name: /Japan 2020/ }))
await waitFor(() => expect(addToast).toHaveBeenCalledWith('Skipped 1 duplicates', 'info', undefined))
await waitFor(() => expect(addToast).toHaveBeenCalledWith('Skipped 1 duplicate', 'info', undefined))
expect(addToast).toHaveBeenCalledWith('Copied 2 places', 'success', undefined)
})
@@ -74,7 +74,7 @@ describe('MBagsSheet', () => {
setup()
expect(screen.getByRole('dialog')).toHaveAttribute('aria-label', 'packing.bags')
expect(within(rowFor('Backpack')).getByText('300 g')).toBeInTheDocument()
expect(within(rowFor('Backpack')).getByText('1 admin.packingTemplates.items')).toBeInTheDocument()
expect(within(rowFor('Backpack')).getByText('1 admin.packingTemplates.items:1')).toBeInTheDocument()
expect(within(rowFor('Suitcase')).getByText('1.2 kg')).toBeInTheDocument()
})
@@ -290,7 +290,7 @@ describe('MBagsSheet', () => {
})
expect(within(rowFor('Backpack')).getByText('200 g')).toBeInTheDocument()
expect(within(rowFor('Backpack')).getByText('1 admin.packingTemplates.items')).toBeInTheDocument()
expect(within(rowFor('Backpack')).getByText('1 admin.packingTemplates.items:1')).toBeInTheDocument()
})
it('FE-MOB-BAGS-024: common items still count for everyone', () => {
@@ -116,7 +116,7 @@ describe('MCollabPolls', () => {
] })])
expect(await screen.findByText('Where to eat?')).toBeInTheDocument()
expect(screen.getByText('collab.polls.vote:1')).toBeInTheDocument()
expect(screen.getByText('collab.polls.votes:1')).toBeInTheDocument()
expect(screen.getByText('collab.polls.multiChoice')).toBeInTheDocument()
})
@@ -217,7 +217,7 @@ describe('MCollabPolls', () => {
fireEvent.click(await screen.findByRole('button', { name: /Ramen/ }))
await waitFor(() => expect(votePoll).toHaveBeenCalledWith(1, 1, 0))
expect(await screen.findByText('collab.polls.vote:1')).toBeInTheDocument()
expect(await screen.findByText('collab.polls.votes:1')).toBeInTheDocument()
expect(screen.getByText('100%')).toBeInTheDocument()
})
@@ -304,7 +304,7 @@ describe('MCollabPolls', () => {
{ text: 'Sushi', label: 'Sushi', voters: [] },
] }),
}))
expect(screen.getByText('collab.polls.vote:1')).toBeInTheDocument()
expect(screen.getByText('collab.polls.votes:1')).toBeInTheDocument()
act(() => handler({ type: 'collab:poll:closed', tripId: '1', poll: poll({ id: 2, question: 'Which hotel?', is_closed: true }) }))
expect(screen.getByText('collab.polls.closed')).toBeInTheDocument()
@@ -208,7 +208,7 @@ describe('MCostSheet', () => {
fillBasics('Taxi', '30')
fireEvent.click(screen.getByRole('button', { name: 'B bob' }))
expect(screen.getByText('Split 1 ways · €30.00 each')).toBeInTheDocument()
expect(screen.getByText('1 person · €30.00')).toBeInTheDocument()
expect(screen.getAllByText('Tap to include')).toHaveLength(1)
fireEvent.click(submit())
@@ -224,7 +224,7 @@ describe('MPackingListTab', () => {
openActions()
fireEvent.click(screen.getByRole('button', { name: 'packing.applyTemplate' }))
expect(screen.getByText('12 admin.packingTemplates.items')).toBeInTheDocument()
expect(screen.getByText('12 admin.packingTemplates.items:12')).toBeInTheDocument()
await act(async () => { fireEvent.click(screen.getByRole('button', { name: /Beach trip/ })) })
// The visibility follows the Shared|My-list toggle so the items land where
@@ -135,7 +135,7 @@ describe('MPlacesSaveToCollectionSheet', () => {
})
renderSheet()
fireEvent.click(await screen.findByText('Favorites'))
await waitFor(() => expect(addToast).toHaveBeenCalledWith('Skipped 1 duplicates', 'info', undefined))
await waitFor(() => expect(addToast).toHaveBeenCalledWith('Skipped 1 duplicate', 'info', undefined))
expect(addToast).toHaveBeenCalledWith('Saved 1 to Favorites', 'success', undefined)
})
@@ -141,16 +141,16 @@ describe('MRtCorridorSheet', () => {
expect(screen.getByText('roadtrip.poi.capped')).toBeInTheDocument()
expect(screen.getByText('roadtrip.poi.partial:2')).toBeInTheDocument()
// The phone's own wording: the desk's ends in "narrow the corridor", and the
// corridor width is a control this screen does not have. One stretch takes the
// singular key, because one key with {count} in it would read as "1 stretches".
expect(screen.getByText('mobileTrip.rtTruncated.one:1')).toBeInTheDocument()
// corridor width is a control this screen does not have. The count goes to t(),
// which picks the form the language needs, so one stretch never reads "1 stretches".
expect(screen.getByText('mobileTrip.rtTruncated:1')).toBeInTheDocument()
expect(screen.queryByText('roadtrip.poi.truncated:1')).toBeNull()
})
it('FE-MOB-RTSRCH-011b: more than one truncated stretch takes the plural key', () => {
it('FE-MOB-RTSRCH-011b: more than one truncated stretch passes its count to the same key', () => {
renderSheet({ answered: true, hits: [hit()], truncatedAreas: 3 })
expect(screen.getByText('mobileTrip.rtTruncated.other:3')).toBeInTheDocument()
expect(screen.getByText('mobileTrip.rtTruncated:3')).toBeInTheDocument()
})
it('FE-MOB-RTSRCH-012: a hit says what it is and where on the drive it sits', () => {
@@ -463,7 +463,7 @@ describe('MTripSheets', () => {
expect(screen.queryByRole('button', { name: 'Delete' })).not.toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Upload' })).not.toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Edit track colour' })).not.toBeInTheDocument()
fireEvent.click(screen.getByRole('button', { name: '1 files' }))
fireEvent.click(screen.getByRole('button', { name: '1 file' }))
expect(screen.getByText('ridge.gpx')).toBeInTheDocument()
expect(Boolean(screen.queryByRole('button', { name: /Add to day/i }))).toBe(dayEdit)
},