wip(i18n): plural forms through Intl.PluralRules

Unfinished, continued in the next session: t() resolves key.one/.few/...
by the language's own plural rule, the parity check knows which forms a
language needs, 16 singular/plural key pairs are merged in every locale
and every count === 1 branch in the client uses the plural form. Still
open: the forms each locale needs for the remaining count strings, the
two new labels in every locale, and 35 tests that expect the old English
wording.
This commit is contained in:
Maurice
2026-10-07 22:57:51 +02:00
parent 588e483205
commit de128cc4ae
271 changed files with 931 additions and 651 deletions
+1 -1
View File
@@ -241,7 +241,7 @@ function PollCard({ poll, currentUser, canEdit, onVote, onClose, onDelete, t }:
{isClosed && <PollChip icon={<Lock size={9} strokeWidth={2.4} />}>{t('collab.polls.closed')}</PollChip>}
{remaining && !isClosed && <PollChip tone="warning" icon={<Clock size={9} strokeWidth={2.4} />}>{remaining}</PollChip>}
{poll.multiple_choice && <PollChip>{t('collab.polls.multiChoice')}</PollChip>}
<PollChip>{t(total === 1 ? 'collab.polls.vote' : 'collab.polls.votes', { n: total })}</PollChip>
<PollChip>{t('collab.polls.votes', { n: total })}</PollChip>
</div>
</div>
{canEdit && (
@@ -56,7 +56,7 @@ export function FilesView(S: FileManagerState) {
}}>{tab.icon ? <tab.icon size={13} fill={filterType === tab.id ? '#facc15' : 'none'} color={filterType === tab.id ? '#facc15' : 'currentColor'} /> : tab.label}</button>
))}
<span style={{ marginLeft: 'auto', fontSize: 'calc(11.5px * var(--fs-scale-caption, 1))', color: 'var(--text-faint)', alignSelf: 'center' }}>
{filteredFiles.length === 1 ? t('files.countSingular') : t('files.count', { count: filteredFiles.length })}
{t('files.count', { count: filteredFiles.length })}
</span>
</div>
@@ -60,13 +60,7 @@ export default function JourneyDayDawarich({
<DawarichIcon size={18} className="shrink-0" />
<span className="min-w-0 flex-1">
<span className="block truncate text-[13px] font-semibold text-content">
{/* Two keys picked by the count, the shape this codebase uses for a number
that changes its noun: there is no plural engine in the i18n layer, and one
key with {count} in it reads as "1 stays". */}
{t(
suggestions.length === 1 ? 'dawarich.journey.dayStays.one' : 'dawarich.journey.dayStays.other',
{ count: suggestions.length },
)}
{t('dawarich.journey.dayStays', { count: suggestions.length })}
</span>
{span && <span className="block text-[11px] text-content-faint tabular-nums">{span}</span>}
</span>
@@ -297,7 +297,7 @@ describe('GalleryView', () => {
await waitFor(() => expect(onRefresh).toHaveBeenCalledTimes(1))
expect(bodies[0]).toEqual({ provider: 'immich', asset_ids: ['asset-1'], media_types: ['image'] })
expect(toastSpy).toHaveBeenCalledWith('1 photos added', 'success', undefined)
expect(toastSpy).toHaveBeenCalledWith('1 photo added', 'success', undefined)
expect(screen.queryByRole('heading', { name: 'Immich' })).not.toBeInTheDocument()
})
@@ -288,7 +288,7 @@ describe('AirTrailImportModal', () => {
await user.click(await screen.findByRole('button', { name: /Import 1/i }));
await waitFor(() => expect(pushUndo).toHaveBeenCalled());
expect(toasts).toContainEqual(['success', '1 flight(s) imported']);
expect(toasts).toContainEqual(['success', '1 flight imported']);
expect(toasts).toContainEqual(['warning', '1 already in this trip, skipped']);
expect(pushUndo.mock.calls[0][0]).toBe('Import from AirTrail');
@@ -247,7 +247,7 @@ describe('AirTrailConnectionSection', () => {
await screen.findByDisplayValue('https://air.example.com');
await user.click(screen.getByRole('button', { name: /Test connection/ }));
await screen.findByText('Connected — 12 flight(s) found');
await screen.findByText('Connected. 12 flights found');
expect(screen.getByText('Connected')).toBeInTheDocument();
expect(body).toEqual({ url: 'https://air.example.com', allowInsecureTls: false });
});
@@ -263,7 +263,7 @@ describe('AirTrailConnectionSection', () => {
await screen.findByDisplayValue('https://air.example.com');
await user.click(screen.getByRole('button', { name: /Test connection/ }));
expect(await screen.findByText('Connected — 0 flight(s) found')).toBeInTheDocument();
expect(await screen.findByText('Connected. 0 flights found')).toBeInTheDocument();
});
it('FE-COMP-AIRTRAIL-015: a refused test shows the returned error and keeps the badge off', async () => {
@@ -319,7 +319,7 @@ describe('OfflineTab', () => {
expect(screen.getByRole('button', { name: 'Downloading…' })).toBeDisabled();
await act(async () => { release(); });
expect(await screen.findByText('Stored 4 trip(s) on this device')).toBeInTheDocument();
expect(await screen.findByText('Stored 4 trips on this device')).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Download for offline use' })).toBeEnabled();
});
+1 -1
View File
@@ -70,7 +70,7 @@ export default function ToursSidebar({ tripId, days, tours, loading = false, sel
// enter the shared store used by the day map.
await onToursChanged?.(result.tours.map(tour => tour.place_id))
await loadTrip(tripId)
toast.success(t(result.tours.length === 1 ? 'tours.import.successOne' : 'tours.import.success', { count: result.tours.length }))
toast.success(t('tours.import.success', { count: result.tours.length }))
if (result.caution) toast.info(t('tours.import.caution'))
} else {
toast.warning(t('places.importAllSkipped'))
@@ -240,7 +240,7 @@ function TripMembersSheet({ isOpen, onClose, tripId, tripTitle, onMembersChanged
<div style={{ display: 'flex', alignItems: 'center', gap: 6, marginBottom: 10 }}>
<Users size={13} className="text-content-faint" />
<span className="text-content-secondary" style={{ fontSize: 'calc(12px * var(--fs-scale-body, 1))', fontWeight: 600 }}>
{t('members.access')} ({realMembers.length} {realMembers.length === 1 ? t('members.person') : t('members.persons')})
{t('members.access')} ({realMembers.length} {t('members.persons', { count: realMembers.length })})
</span>
</div>
@@ -41,7 +41,7 @@ function OpenDialog({ onClose, tripId, tripTitle, onMembersChanged }: TripShareD
const labelId = useId()
const m = useTripMembers({ isOpen: true, tripId, onClose, onMembersChanged })
const [ask, setAsk] = useState<Ask | null>(null)
const persons = `${m.realMembers.length} ${m.realMembers.length === 1 ? t('members.person') : t('members.persons')}`
const persons = `${m.realMembers.length} ${t('members.persons', { count: m.realMembers.length })}`
return (
<>