F182: i18n infrastructure (SPA foundation) — react-i18next, coordinated bootstrap, errorCodes, pilot#233
Open
mforce wants to merge 12 commits into
Open
F182: i18n infrastructure (SPA foundation) — react-i18next, coordinated bootstrap, errorCodes, pilot#233mforce wants to merge 12 commits into
mforce wants to merge 12 commits into
Conversation
added 12 commits
July 25, 2026 23:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The SPA i18n foundation for #182 — the plumbing so screens add catalog keys instead of hardcoded strings, and the stored §4.5 language finally drives display. English-only; no second language ships here.
What this adds
src/i18n/en.ts) — namespaced (common/auth/sales/account/errors),CustomTypeOptionsmakest("typo")a compile error,keySeparator:false(theerrorskeys are dotted API codes), init-once singleton withfallbackLng:"en"(missing key → English, never blank/raw key).src/session/SessionContext.tsx) — insideProtectedRoute,SessionProviderreads/me+/accountviaPromise.allSettled, resolves the UI language (me.language→ farm-locale subtag → English, case-insensitive, pack-gated), callsi18n.changeLanguage, and gates the shell (if (!result) return null) until the language is set — so the authenticated shell never paints one English frame first. It hands the account toFarmProvider(new tri-stateinitialAccount) so/accountis read once.MeContext/useMeexpose the user.parseError→ catalog (src/api/client.ts) — mapserrorCodes(from i18n infrastructure (API half): validation error codes + users.language + GET/PATCH /me #45) to catalog messages, index-aligned with a per-slot English fallback (i18n.t(key, {defaultValue: serverMsg}));ApiError.messagestays a single flattened string (all ~30 consumers untouched).PUT /me/language, hidden while English-only (renders nothing until a second pack ships).Login.tsx+SalesPage.tsxexternalized (111saleskeys) as the worked pattern;t()for plain,<Trans>for JSX-interleaved,t(key,{var})for interpolation.web/CONTRIBUTING-i18n.md— thet()/<Trans>convention, key naming, the formatting boundary, the singleton-for-non-render rule.Deliberate decisions
SessionProviderowns the single/accountread and seedsFarmProvider(not two independent providers) — this is what closes the flash window and avoids a double fetch.FarmProvider's standalone self-fetch path is preserved for its own tests.Promise.allSettled, notall— a/mefailure preserves a good/account(its timezone/locale drive date correctness) and vice versa; only an account-read failure surfaces FarmProvider's banner.renderWithProviders(the i18n wiring point) and it exercises dialogs/tables/interpolation/role-gating.src/lib/src/farm100,src/auth,src/api/client.ts) lowered.Out of scope (tracked follow-ups in #182)
StatusBadge, payment method, unit) — invisible today (enum === English label), a completeness gap for the first non-English pack.Testing
npm run test:coverage643 tests green; coverage 84.24% stmts / 73.91% branches / 78.27% funcs / 87.66% lines (above floors);npm run typecheckclean;npm run buildsucceeds. New coverage: catalog fallback, resolution chain (case-insensitive), no-flash gating + independent-settle + cancellation (observable-effect assertion),parseErrorcode→message + index-alignment + English fallback, formatting-independence guard, hidden + multi-language selector.Review
Reviewed per policy — plan reviewed pre-execution (codex + pi + Claude; findings folded in before any code), each of the 9 tasks task-reviewed, then a whole-branch review by two Claude agents + pi (all ready to merge; codex's run produced no usable verdict). One real (dormant) bug the reviews caught — the language selector read a stale
me.languageand would snap back after a switch — was fixed in this PR (current = i18n.language) with a regression test, since the selector is unreachable while English-only but would bite the moment a pack ships. Persist/switch failures now log rather than swallow.