I18N-P0 / I18N-P1 — English framework and French switcher (design)
Version: 1.6
Last Updated: 2026-08-04 18:12:44
Status: I18N-P0 extraction complete; I18N-P1 switcher + Intl helpers + locale smoke pack in place
Spec: 03-REQUIREMENTS-INTERNATIONAL-LANGUAGE.md (normative; REQ-IDs authoritative)
Roadmap: 04-ROADMAP §15 · Phase 3
Architecture: 01-ARCHITECTURE.md — Internationalisation architecture
This document is the design for the first two phases of the international language programme. It does not restate doc 03; it records the engineering decisions, the measured scope, and the deviations from doc 03 that were agreed on 2026-08-03. The implementation plan is a separate artefact.
1. Why now, and what is in scope
Section titled “1. Why now, and what is in scope”Doc 03 is complete as a product specification (REQ-I18N-01…38, build order locked). The §4.1 foundation is implemented and §3.3 extraction batches 1–20 are complete (react-i18next + t() across pages/components; ESLint i18n ratchet holds two intentional permanent exempts). I18N-P1 engineering (locale persistence, switcher, Intl helpers) is in progress. Wave 1b locale plug-ins (I18N-P2a/P2b), marketing language (I18N-M1), backend template localisation (I18N-BE), and Wave 2+ RTL/CJK remain roadmap phases and are not designed here.
Timing decision. P0 starts now rather than after the A6 launch gate, with the C7 English Register R2 audit running in parallel. C7 must land before any non-English locale is enabled. The reasoning is that English wording changes are nearly free while en-AU is the only locale, and expensive once translations exist — every re-voiced English string invalidates its translation in every shipped language.
Working constraint. Feature work on other tracks (Care Pathways, Care Start, vitals) continues throughout. Extraction must therefore be incremental and conflict-tolerant; a codebase-wide freeze is not available.
1.1 Product decisions locked (2026-08-03)
Section titled “1.1 Product decisions locked (2026-08-03)”| Topic | Decision |
|---|---|
| Clinical view toggle | Not shipping — plain register only; REQ-I18N-18/19 and mandatory _clinical pairs deferred (doc 03 v1.7). |
| Observation instruments | LynCareOS-owned carer-observation copy; Abbey/PAINAD/Rockwood/NRS are references only — no verbatim instrument lists (doc 03 v1.8, i18n-frontend.mdc). |
| Marketing hreflang | In scope for I18N-M1 — REQ-I18N-32a: locale path prefixes + link rel="alternate" hreflang including x-default. |
| Pre-login language | Marketing static HTML (marketing/palliative/) — detect + top-right picker; lyncareos_marketing_locale cookie flows into app bootstrap (doc 03). |
| Locale bundles | fr-FR stays enabled: false until product enables locally; non-English JSON is produced only when you ask — English extraction/CI still mandatory for new UI. |
| C7 | Run in parallel with P0; not a pre-launch blocker for English-only production. |
| PostgreSQL REINDEX | Standard ops after VPS OS upgrade — 07-PLATFORM-RUNBOOK §18 (done 2026-08-03). |
2. Measured scope
Section titled “2. Measured scope”Measured against the repository on 2026-08-03. String and word counts below are regex-derived estimates (JSX text nodes, placeholder/aria-label/title/label props, and broad quoted literals). They guide planning only; the authoritative key count is i18next-cli status after the foundation PR lands.
| Metric | Value |
|---|---|
.tsx files under frontend/src | 305 (52 pages, 197 components) |
Lines of TypeScript under frontend/src | ~95,600 |
| Candidate translatable strings (estimate) | ~3,270 |
| Candidate source words (estimate) | ~13,700 |
| Files containing JSX text or string props | 177 |
| i18n dependencies present today | none |
tenants.locale / users.locale_override | V031 (I18N-P1 engineering) |
Planning figures after deduplication and false-positive filtering: 2,500–3,500 keys, 12,000–15,000 source words. This is a small-to-medium localisation project; the dominant cost is engineering, not volume.
Milestone A carries the whole programme’s engineering cost. Once extraction is complete and the plug-in model works, each additional Latin or Cyrillic locale is translation files plus a config flag, per REQ-I18N-33.
3. Decisions
Section titled “3. Decisions”3.0 Translation happens once, ahead of time — never at runtime
Section titled “3.0 Translation happens once, ahead of time — never at runtime”Stated explicitly because it underpins every other decision.
Translation is build-time. English strings are extracted once, translated once per locale, reviewed, committed to git, and bundled as static JSON. At runtime the app performs a dictionary lookup, not a translation: selecting French loads fr-FR/*.json (a few kB) and i18next resolves t('medication.dose.confirm_button') against it. There is no call to any translation service, no AI in the request path, no added latency, and it works offline in the PWA. The switch is instant and does not reload the app or end the session.
The AI translation described in §3.8 is an authoring tool used before release — analogous to using AI to help write code. It drafts locale JSON, a human reviews it, the result is committed. End users never interact with a translation model, and no user data ever reaches one.
| Dimension | One-time / build-time (adopted) | Real-time / on-the-fly (rejected) |
|---|---|---|
| When translation occurs | Once per string, before release | Every page view, indefinitely |
| Runtime cost | Zero | Per request, scales with usage |
| Latency | None — local lookup | Network round trip per screen |
| Offline / PWA | Works | Breaks |
| Determinism | Identical wording every time | May vary between sessions |
| Human review | Yes, before shipping | None — unreviewed text reaches carers |
| Data exposure | UI keys only | Content leaves the platform — disqualifying, see §3.5 |
Two consequences.
- User content is never translated at any stage — not at build time, not at runtime. A care note typed in Russian is stored and displayed as Russian to every reader regardless of their UI language (§3.5, REQ-I18N-16).
- New features do not arrive translated. Strings added after a locale ships exist only in
en-AUuntil translated, and fall back to English per REQ-I18N-03 in the meantime. This is the recurring maintenance load described in §3.8 and §6 — a direct consequence of this model, and the price of every advantage in the left-hand column above.
3.1 Library: react-i18next with the ICU plugin
Section titled “3.1 Library: react-i18next with the ICU plugin”react-i18next remains correct for a Vite + React 19 SPA — it is the universal choice (~8M weekly downloads) and the alternatives that outperform it (next-intl) are Next.js-only. This confirms REQ-I18N-01.
Deviation added: the i18next-icu plugin is adopted from the first key. i18next’s native message format is non-standard where the localisation industry uses ICU MessageFormat, which creates friction with translation platforms. Since REQ-I18N-36 anticipates a TMS from I18N-P2a, standardising plurals and select syntax now costs nothing and avoids rewriting every plural in every locale later.
3.2 Extraction: i18next-cli in reviewed batches, behind two lint ratchets
Section titled “3.2 Extraction: i18next-cli in reviewed batches, behind two lint ratchets”Custom ts-morph codemods are not required. The official i18next-cli (v1.47+) provides the whole toolchain:
| Need | Command | Requirement satisfied |
|---|---|---|
Codemod hardcoded strings into t() | i18next-cli instrument | — |
| Build namespace JSON from source | i18next-cli extract | REQ-I18N-02 |
| Generate typed keys | i18next-cli types | REQ-I18N-04 |
| Detect remaining hardcoded strings | i18next-cli lint | — |
| Per-namespace coverage reporting | i18next-cli status | REQ-I18N-34 |
The maintainers’ own guidance matches the batch model: run --dry-run, then --interactive to approve each candidate, commit, then extract. They describe instrument as “a first-pass assistant, not a compiler” and require diff review.
Key naming stays human. instrument derives keys from content (a button reading “I am button” becomes iAmButton). Machine keys are effectively permanent — every locale file, TMS entry, and reviewer’s context is built on them — so each batch includes a pass renaming keys to semantic, hierarchical names (medication.dose.confirm_button).
Two ratchets, both modelled on the existing overlay z-index migration in frontend/eslint.config.js (rule on globally, shrinking list of exempt files, CI fails if the list grows):
- No literal user-facing text in
src/pagesandsrc/components(eslint-plugin-i18nextno-literal-string). - No physical-direction Tailwind classes (
ml-,mr-,pl-,pr-,left-,right-,text-left,text-right) in favour of logical equivalents (ms-,me-,ps-,pe-,start-,end-,text-start,text-end) — REQ-I18N-12 / NFR-12.
Un-migrated files stay legal so feature work is never blocked; migrated files can never regress. Progress is monotonic by construction.
RTL readiness runs inside P0, not at Wave 2. Retrofitting logical CSS later means touching all 305 files a second time. No RTL locale ships in P0 or P1; only the CSS and component conventions land.
3.3 Batch order
Section titled “3.3 Batch order”Roughly twenty day-sized PRs (~15 files each), one domain per batch, each adding namespace JSON and shrinking both ratchet exemption lists.
Batch 1 — app shell (mandatory first): components/layout, components/ui, components/brand, plus root-level auth/onboarding pages (Login.tsx, Register.tsx, PendingApproval.tsx, GettingStarted.tsx). Establishes bidi display conventions (§3.6) and key naming before the long tail.
Suggested batch spine (batches 2–20; merge small dirs where sensible):
| Batch | Scope | Namespace(s) |
|---|---|---|
| 2 | components/auth + pages/Account.tsx | modules/auth, common (account) |
| 3 | components/settings + team/invite flows | modules/settings |
| 4 | components/billing + billing pages | modules/billing |
| 5 | components/dashboard + Dashboard.tsx, More.tsx | modules/dashboard |
| 6 | components/medication, dose, logDose + LogDose.tsx | modules/medication |
| 7 | components/scripts + Scripts.tsx, ScriptDetail.tsx | modules/scripts |
| 8 | components/medication-schedule + MedicationSchedule.tsx, AutoDispense.tsx | modules/medication-schedule |
| 9 | components/calendar + Calendar.tsx, Schedule.tsx, pages/calendar/* | modules/calendar |
| 10 | components/shopping + Shopping.tsx | modules/shopping |
| 11 | components/vitals + VitalsTracking.tsx | modules/vitals |
| 12 | components/pain + PainTracking.tsx | modules/pain |
| 13 | components/observations + Observations.tsx | modules/observations |
| 14 | components/familyHelp + HelpRequests.tsx, KeyContacts.tsx | modules/familyHelp |
| 15 | components/sleep + SleepPattern.tsx | modules/sleep |
| 16 | components/history + History.tsx, pages/history/* | modules/history |
| 17 | components/alerts, notifications | notifications, errors (shared chrome) |
| 18 | components/condition-packs, care-modules, care-capture | modules/condition-packs, clinical |
| 19 | components/admin + pages/admin/* | modules/admin |
| 20 | components/charts, radar, remaining root pages, context/ copy | sweep + common/errors completion |
Namespaces follow REQ-I18N-02: core common, clinical, errors, notifications, plus modules/{slug}.json per product domain. Adjust batch boundaries if a PR exceeds ~300 lines of meaningful diff.
Clinical-register strings use plain keys only for P0/P1 (REQ-I18N-02a deferred with the clinical toggle). Palliative Register R2 still applies to English seed copy during extraction.
3.4 Locale detection: browser language first, country as a weak hint
Section titled “3.4 Locale detection: browser language first, country as a weak hint”This corrects a common but incorrect intuition that a user located in France should receive a French UI. Country is not language. The 2026 guidance is consistent: prioritise Accept-Language / navigator.languages over IP geolocation, and use geolocation only for regional formatting such as currency, never for language selection. VPNs, travel, expatriates, and diaspora households break country inference immediately.
This matters specifically for LynCareOS. Family carers include migrant and diaspora households — doc 03 itself uses the Russian-speaker-in-a-UK-household example. Under a country-first rule, a British family caring for a relative in France would receive a medication interface in French. That is a safety-relevant failure, not a cosmetic one.
Resolution order. Doc 03 §9 defines a four-step chain for the app and REQ-I18N-28 defines a five-step chain including a country hint for marketing. This design harmonises them on the marketing form, so app and marketing behave identically. The order must not be weakened during implementation:
users.locale_overridetenants.localenavigator.languages, matched against enabled locales- Country hint (Cloudflare
CF-IPCountryor existing IP pricing lookup), where the config defines a default locale for that country en-AU
Matching uses @formatjs/intl-localematcher rather than string comparison, so fr-CA resolves to fr-FR and en-IE to en-AU through CLDR rules (UTS #35). This is how REQ-I18N-06 locale inheritance is implemented in practice.
Where the country hint disagrees with the resolved language, the app shows a dismissible suggestion (“also available in Français”) rather than switching silently. The intended outcome is preserved — a person living in France almost always has French in their browser language list — while removing the failure mode where the guess is wrong.
The resolved locale is written to a cookie as well as the user profile, so the first paint after login does not flash English.
3.5 User content is never translated — a security boundary, not a preference
Section titled “3.5 User content is never translated — a security boundary, not a preference”REQ-I18N-16’s frame-versus-content separation is restated here as a hard rule, because the healthcare research makes it a compliance control rather than a UX choice:
- Health data is GDPR “special category” data. Sending patient-entered free text to any external translation service — a TMS, a machine-translation API, or an LLM — without a signed BAA or DPA is a direct GDPR and HIPAA exposure.
- Measured machine-translation error rates on medical content run 2–8%, which is unacceptable for clinical text regardless of the legal position.
Rule: translation tooling — including AI models used under §3.8 — sees en-AU UI keys and nothing else, ever. No user content, no PHI, no database extract leaves the platform for translation purposes. This constrains any future TMS selection at I18N-P2a.
Storage is already correct and verified. Both the Docker UAT database (PostgreSQL 16.11) and production (16.14, verified read-only 2026-08-03) use UTF8 encoding, so text in any script stores losslessly today. No migration is required for content storage.
3.6 Bidirectional text display
Section titled “3.6 Bidirectional text display”dir="auto" on user text inputs (REQ-I18N-20) is necessary but not sufficient. When RTL user content is displayed adjacent to LTR frame text, direction bleeds into surrounding layout unless each user string is isolated.
Convention, established in batch 1: wrap displayed user-entered content in <bdi> (or an element carrying dir="auto"); where user text is concatenated into a plain string, use Unicode isolation characters FSI (U+2068) and PDI (U+2069). This has no visible effect until Wave 2 but avoids a second pass over every component.
3.7 Collation caveat (operations, not i18n)
Section titled “3.7 Collation caveat (operations, not i18n)”Both databases use glibc collation (en_US.utf8). Storage is unaffected, but sort order of non-ASCII text depends on the host’s glibc version, and a VPS OS upgrade can silently corrupt text indexes until a REINDEX. Changing collation requires recreating the database, so the correct response is a documented REINDEX step in the OS-upgrade procedure. The risk exists today; it becomes material once significant non-Latin data is held.
Action: Done — 07-PLATFORM-RUNBOOK.md §18, 11-DATABASE-SAFETY §2q, 20-PRODUCTION-DEPLOYMENT-GUIDE §7.
3.8 Translation quality model: AI consensus plus native review
Section titled “3.8 Translation quality model: AI consensus plus native review”This deviates from doc 03 §7.8 as previously written (professional translator mandate). Doc 03 §7.8 / §7.8a was amended in v1.6 to match this model.
Evidence supporting the change:
- LLMs reach 85–95% of professional human quality, and UI strings are the strongest case — “for UI strings, technical documentation, and help articles, AI quality often suffices without human review.” The residual 10–20% human advantage concentrates in marketing and creative copy.
- Multi-model consensus (querying several independent engines and taking agreement) reduced visible errors and stylistic drift by 18–22% versus a single engine, with the largest gains in hallucinated content, dropped words, and terminology drift.
- Human post-editing of LLM output adds roughly 8%, concentrated in naturalness and cultural fit — precisely what a machine cannot self-assess.
- Doc 03’s Tier 2 standard is already “translator plus lay carer native review,” tested by “would a family member say this?” A native-speaker family carer is better placed to make that register judgement than a certified medical translator, who tends to correct toward clinical register.
Model adopted:
| Tier | Content | Production | Review |
|---|---|---|---|
| 1 — UI chrome | Nav, buttons, settings, errors | Multi-model AI consensus + automated back-translation diff | Native-speaker spot review: every high-risk string plus a sample of ≥10% of keys per namespace |
| 2 — Plain clinical | Prompts, observation labels (plain keys) | Multi-model AI consensus | Mandatory native lay-carer review, reviewer ≠ translator |
| 3 — Verbatim validated instruments (exception) | Official Abbey/PAINAD/Rockwood/NRS text only if product opts in | Not translated by AI or volunteers | Licence + official translation; not the default product path |
Carer-observation default (doc 03 v1.8): Future modules use LynCareOS-owned descriptors inspired by literature — Tier 2 — avoiding verbatim instrument reproduction. See Appendix A and i18n-frontend.mdc.
Three controls make the zero-cash model safe:
- Glossary and do-not-translate list, built during P0 while English keys are being written. Volunteer and AI translation both drift on terminology without one.
- Automated back-translation diff in CI — machine catches semantic drift so humans do not have to read 3,000 strings.
- High-risk string set — anything concerning dose, timing, allergy, or emergency contact always receives human review from a second person, with the reviewer never being the translator.
Sustainability risk, stated explicitly. This is a permanent obligation, not a one-off favour. Community-translation experience is consistent: a motivated volunteer translates a large chunk over a weekend and then abandons it, leaving fragmented strings; the Scratch Foundation found 3–12 people per language are needed to sustain the effort. Every release adds strings. The mitigation is to keep the enabled locale count small until a market justifies the permanent maintenance load, and to let CI coverage gates block a locale rather than shipping it half-translated.
Tooling. glossboss (open source) handles i18next JSON natively, supports DeepL, OpenAI, Claude and Gemini, and provides translation memory, glossary conflict checks, ICU variable drift detection, and a review workflow with GitHub sync. It replaces the paid TMS line item for P0–P1.
4. I18N-P0 — English framework
Section titled “4. I18N-P0 — English framework”4.1 Foundation change set (touches almost no existing files)
Section titled “4.1 Foundation change set (touches almost no existing files)”| Artefact | Purpose |
|---|---|
frontend/src/lib/i18n.ts | i18next init, ICU plugin, detector chain (§3.4), changeLanguage wrapper |
frontend/src/locales/en-AU/{common,clinical,errors,notifications}.json | Core namespaces (REQ-I18N-02) |
frontend/src/locales/locales.config.json | en-AU only, full REQ-I18N-05 shape: nativeDisplayName, flagEmoji, direction, extends, enabled, date/time/number formats, week start, emergency number, terminology map |
Generated resources.d.ts + i18next CustomTypeOptions | Typed keys; t() typos become build errors (REQ-I18N-04) |
i18next.config.ts | i18next-cli configuration |
| ESLint ratchet configs + baseline lists | §3.2 |
frontend/src/locales/glossary.json | Termbase and do-not-translate list (§3.8) |
Runtime behaviour implemented once and not revisited: the REQ-I18N-03 fallback chain with the visible [MISSING: key] sentinel, and the REQ-I18N-35 three-second lazy-load timeout falling back to en-AU per namespace.
4.2 Sweep
Section titled “4.2 Sweep”Twenty batches per §3.3. Each batch: instrument --dry-run, instrument --interactive, semantic key rename, interpolation and plural fixes, extract, types, shrink both ratchet lists, merge. Run npm run validate:architecture in frontend/ before merge on every batch.
4.4 Quality gates and CI
Section titled “4.4 Quality gates and CI”The design references “CI blocks the flip” (REQ-I18N-34) and ratchets (§3.2). Wire them into the repo’s existing automation — do not invent a parallel process.
Local — scripts/run-quality-gates.ps1 (today: Ruff, Router SQL, Tenant isolation, Audit trail, SELECT *, Pytest, ESLint strict, OpenAPI type drift, Vitest). Add Run-Step entries in the foundation PR or first ratchet PR:
| Step | Command / script | Purpose |
|---|---|---|
| i18n coverage | npx i18next-cli status (fail under §7.8 thresholds when checking release branches) | REQ-I18N-34 |
| i18n lint ratchet | ESLint with shrinking exempt list for eslint-plugin-i18next | No new hardcoded frame strings in migrated files |
| logical-CSS ratchet | ESLint rule + baseline JSON (same pattern as overlay z-index exempt list in frontend/eslint.config.js) | REQ-I18N-12 / NFR-12 |
| back-translation diff | frontend/scripts/ gate script (P1): diff machine back-translation of locale JSON vs en-AU | §3.8 control 2 |
CI — .github/workflows/ci.yml (jobs today: ruff, knowledge-alignment, pytest, openapi-contracts, vitest, eslint, …):
- Ratchets ride the existing
eslintjob once rules and baselines live ineslint.config.js. - Add a dedicated
i18njob (or extendvitestonly if it stays fast):i18next-cli status, optional pseudo-localisation check, back-translation diff on PRs touchingfrontend/src/locales/. - Document new steps in 12-CI-REFERENCE.md in the same change set that adds the job.
Architecture ESLint: npm run validate:architecture on src/pages and src/components must stay green throughout the sweep (repo Definition of Done; not inside run-quality-gates.ps1 today).
4.5 Existing test impact
Section titled “4.5 Existing test impact”Vitest and Playwright (npm run test, npm run test:e2e, test:regression) assert on visible English copy today. Extraction must keep en-AU user-visible output identical to pre-extraction wording unless C7 deliberately re-voices a string.
| Situation | Policy |
|---|---|
Test selects by t() key or role/name from unchanged English | Update locator only if the accessibility name changes |
| Snapshot or string equality on frame copy | Fix in the same batch as the extraction that changed the source |
| C7 changes English after keys exist | Update en-AU JSON + tests + any enabled locale in one change set |
| Flaky test | Never weaken an assertion to green the build; fix the test or the copy |
Playwright locale smoke pack (I18N-P1+): npm run test:e2e:i18n — language-agnostic coverage of switcher + html lang persistence, chrome nav.home, day-strip month label, and timeFormat 12h/24h config contract for every enabled non-default locale (e2e/i18n-locale-smoke.spec.ts). Not a full UI crawl.
4.6 Exit criteria
Section titled “4.6 Exit criteria”- No hardcoded user-facing strings remain in
src/pagesorsrc/componentsexcept two intentional permanent ESLint ratchet exempts:BrandWordmark(brand identity) andShoppingCatalogAdmin(catalog l10n deferred per §7). Ratchet lists are not empty by design. i18next-cli statusreports 100%en-AUcoverage across every namespace (plain keys;_clinicalnot required while toggle deferred).- Missing-key smoke test renders the sentinel, not a blank or an error boundary.
- Pseudo-localisation runs clean within the doc 03 §11 expansion caps (150% UI chrome, 200% labels and buttons).
- C7 Register R2 audit complete or explicitly signed off as not blocking.
I18N-P0 extraction exit (2026-08-04): batches 1–20 complete; Vitest 482+; validate:architecture green; ratchet 2/2 permanent exempts only.
5. I18N-P1 — French and the switcher
Section titled “5. I18N-P1 — French and the switcher”5.1 Persistence
Section titled “5.1 Persistence”GET /api/auth/me and PATCH /api/auth/me already exist, with a ProfileUpdate model and an update_profile service, and /me is already the app-load bootstrap call. Locale persistence extends that path rather than adding new plumbing.
| Change | Detail |
|---|---|
V031__i18n_locale_columns.sql | tenants.locale TEXT NOT NULL DEFAULT 'en-AU'; users.locale_override TEXT NULL |
| Migration register | Row added to doc 11 §1a; DDL mirrored into backend/schema.sql |
models.py | locale_override on ProfileUpdate and UserProfile; effective locale on the /me payload |
| Service / repository | update_profile handles locale_override; repository performs the write, scoped by tenant_id |
| Tenant default | tenants.locale editable by tenant admins in Settings (e.g. Account / settings surfaces) |
Returning the resolved effective locale from /me means the client never recomputes the chain.
OpenAPI contract (mandatory in the same commit as model changes). Adding fields to ProfileUpdate / UserProfile changes the published schema. REQ-PLAT-10 / B1 and CI job openapi-contracts fail on drift unless you regenerate and commit together:
python backend/scripts/export_openapi.pycd frontend; npm run generate:typesCommit openapi/openapi.json and frontend/src/lib/api.types.ts together. Add a named alias in frontend/src/lib/api.contracts.ts for any new response fields the client uses (e.g. effective locale); use import type in frontend/src/lib/api.ts — do not hand-edit api.types.ts.
Audit and tenant isolation. Locale preference is not patient-linked clinical data. Updating users.locale_override or reading effective locale for UI bootstrap does not require an audit log entry under the clinical mutation rules in .cursor/rules/rules.mdc. Reviewers and scripts/check_audit_trail.py should treat these endpoints as profile preference, not dispensings/prescriptions/care shifts. tenants.locale writes are tenant-admin only, scoped by tenant_id in the service/repository layer; users.locale_override updates only the authenticated user’s row.
5.2 Language switcher
Section titled “5.2 Language switcher”frontend/src/components/i18n/LanguageSwitcher.tsx — presentation only, reading enabled locales from locales.config.json.
Visibility. When only en-AU is enabled, the control is hidden (no pointless single-language picker). It appears when two or more enabled locales exist — same rule as marketing REQ-I18N-26 / REQ-I18N-27.
Overlay compliance. The open picker is an overlay. Follow 04-OVERLAY-REGISTER.md: short centred pickers are tier D1 (Modal.tsx or listbox with equivalent a11y). Placement is in MobileTopBar.tsx / desktop chrome (z-chrome, 40). The picker panel and backdrop must use a named rung from frontend/tailwind.config.js above z-chrome (e.g. z-sheet / z-dialog) — not ad-hoc z-[N]. Use TenantSwitcher.tsx as the interaction precedent for header placement; do not copy its dismiss layer at z-40 tying the top bar (documented open defect in the overlay register).
| Element | Behaviour |
|---|---|
| Closed control | flagEmoji + nativeDisplayName + chevron (REQ-I18N-22) |
| Open picker | Every enabled locale; native name primary, gloss in active UI language secondary, checkmark on current row (REQ-I18N-23) |
| Sort | Alphabetical by nativeDisplayName via Intl.Collator — never by flag, country, or market priority (REQ-I18N-31) |
| Placement | Top app bar, plus Settings → Language on Account or equivalent (REQ-I18N-21) |
| On select | changeLanguage, update documentElement.lang and dir, aria-live announcement, persist to profile, no logout, other household members unaffected (REQ-I18N-24) |
| Override notice | Settings explains when the personal language differs from the family default, with a reset action (REQ-I18N-25) |
| Accessibility | aria-haspopup, aria-expanded, aria-current; focus trap; Escape closes; rows ≥44 px |
5.3 Display formatting and terminology (REQ-I18N-07, REQ-I18N-08)
Section titled “5.3 Display formatting and terminology (REQ-I18N-07, REQ-I18N-08)”Doc 03 §10 assigns I18N-P1: format dates, numbers, and relative times from locale config; regional terms from the terminology map — not hardcoded “GP” / “PBS” strings in components.
| Area | Approach |
|---|---|
| Dates and times | Prefer Intl.DateTimeFormat, Intl.NumberFormat, Intl.RelativeTimeFormat with locales.config.json options (week start, 12/24h). API continues to return UTC ISO strings and raw numbers. |
date-fns | Repo already depends on date-fns v4. Introduce a small helper (e.g. lib/formatLocale.ts) that picks date-fns/locale/* from the active BCP-47 tag or delegates display-only paths to Intl — avoid two conflicting formats on the same screen. |
| Terminology | Read regional labels from locales.config.json → terminology (REQ-I18N-08); keys in JSON reference terminology slots, not inline country-specific nouns. |
| Scope for P1 | Calendar, medication schedule, billing/Stripe display, and settings surfaces first; expand with each module batch if any remain English-formatted at P1 ship. |
5.4 French bundle
Section titled “5.4 French bundle”fr-FR covering Tier 1 and Tier 2 per the §3.8 model. Tier 3 scales use published validated translations or fall back to English. en-AU must report 100% coverage before fr-FR may be set enabled: true; the i18n CI job / i18next-cli status gate blocks the flip (REQ-I18N-34).
5.5 Exit criteria
Section titled “5.5 Exit criteria”- A user switches
en-AU↔fr-FR; UI changes immediately; reload preserves the choice; a second user in the same household still sees the tenant default. - Lazy-load failure simulation falls back to
en-AUwithin three seconds without breaking the shell. - Native lay-carer review of Tier 2 French complete; high-risk string set reviewed by a second person.
- Back-translation diff clean, or every flagged divergence explicitly accepted.
5.6 Service worker, caching, and deploy verification
Section titled “5.6 Service worker, caching, and deploy verification”Locale strings are static assets, not a runtime translation API. Default implementation for P0/P1:
- Primary path: import locale namespaces via Vite so JSON is content-hashed under
/assets/and participates in normal SPA cache busting on each production build. - Lazy-load path (REQ-I18N-35): if a namespace is loaded with
import()at runtime, treat failed/slow fetch like doc 03 — fall back toen-AUwithin 3s; do not add locale JSON to the service worker precache list unless product explicitly requires offline-first for non-English (would require versioned precache updates per locale ship).
frontend/public/sw.js precaches APP_SHELL and uses runtime caching for navigations. Do not rely on stale SW caches for index.html / sw.js — production already uses no-store on the shell (production-deploy-cache.mdc). Any i18n release that changes UI copy is a UI release: after VPS deploy, verify new CACHE_NAME on https://app.lyncareos.com/sw.js, no-store on /, and API smoke — same gate as other frontend ships.
The offline claim in §3.0 holds when the active locale bundle is either in the main chunk graph or successfully lazy-loaded once; it does not require live translation services.
6. Costs
Section titled “6. Costs”| Item | Cost |
|---|---|
| I18N-P0 engineering tooling | $0 — open source |
| French translation (§3.8 model) | $0 cash; native-speaker review time |
| TMS | $0 — glossboss, self-hosted or local |
| Infrastructure | $0 — static JSON on existing hosting; marginal bundle increase |
| Tier 3 validated scales | Permission and possible commercial licence fees, when those scales ship — independent of language |
| Recurring | Every release adds strings across every enabled locale, forever |
For reference, the professional alternative would be roughly USD $2,500–$5,000 per language all-in, or $18,000–$35,000 for all seven Wave 1b languages.
7. Out of scope
Section titled “7. Out of scope”Tracked as existing roadmap phases, not designed here:
- I18N-BE — backend notification, email, and API error strings (REQ-I18N-11)
- I18N-M1 — marketing site language picker (REQ-I18N-26…30, 32, 32a, 37); hreflang and locale URL prefixes in scope (REQ-I18N-32a)
- I18N-P0v — English regional variants (
en-GB,en-US, …) asextendsoverrides - I18N-P2a/P2b — Wave 1b locale plug-ins
- I18N-P4 — Wave 2+ RTL (Arabic) and CJK. Bidi conventions land in P0; no RTL locale ships.
- Shopping catalog UI locale — backend V012 accepts
?locale=on catalog APIs; UI remains English until a dedicated shopping l10n pass (doc 03 §2.1 deferral). Do not block P0/P1 on catalog string extraction unless product reprioritises.
8. Risks
Section titled “8. Risks”| Risk | Mitigation |
|---|---|
| Extraction stalls partway, leaving a half-migrated codebase | Ratchet lists make progress monotonic and visible; each batch is independently shippable |
| Machine-generated key names become permanent | Semantic rename pass is mandatory in every batch before merge |
| English re-voicing after translation exists | C7 runs in parallel with P0 and gates the first non-English locale |
| Volunteer reviewer availability lapses | CI coverage gate blocks enabling a locale rather than shipping it partial; keep locale count small |
| Terminology drift across AI and volunteer contributions | Glossary and do-not-translate list from P0; glossboss glossary conflict checks |
| Mistranslated safety-critical string | High-risk string set with mandatory second-person review; back-translation diff in CI |
| Merge conflicts with parallel feature work | One domain per batch, day-sized PRs |
| glibc collation drift on OS upgrade | REINDEX in runbook §18 + doc 11 §2q (documented) |
9. Documentation changes required
Section titled “9. Documentation changes required”| Document | Change | When |
|---|---|---|
| 03-REQUIREMENTS-INTERNATIONAL-LANGUAGE.md §7.8 | Replace the professional-translator mandate with the §3.8 AI-consensus plus native-review model and its three controls | Done — doc 03 v1.6 |
| Doc 03 §4 current state | Update once P0 lands | End of P0 |
| Doc 03 §7.1 / REQ-I18N-01 | Note i18next-icu adoption and the i18next-cli toolchain | Done — doc 03 v1.6 |
| Doc 03 §9 effective locale resolution | Add the country-hint step so the app chain matches REQ-I18N-28 (§3.4) | Done — doc 03 v1.6 |
| 12-CI-REFERENCE.md | Document new i18n CI job and local gate parity | When CI job lands |
| Project Motherboard / knowledge alignment | Run .\scripts\run-knowledge-assessment.ps1 after doc 03 v1.6; reports under knowledge/reports/; CI knowledge-alignment job | After doc 03 publish (same release as design v1.2) |
| 04-ROADMAP §15 | Status Not started → In progress | P0 start |
| 01-ARCHITECTURE.md Internationalisation section | Current state and the new tenants.locale / users.locale_override columns | End of P1 |
| doc 11 §1a | Register V031__i18n_locale_columns.sql | With the migration |
| 07-PLATFORM-RUNBOOK.md | REINDEX step in the OS-upgrade procedure (§3.7) | Done — §18 |
| 31 delivery register §2.41 | REQ-I18N status updates | Per phase |
10. Effort estimate (planning)
Section titled “10. Effort estimate (planning)”Order-of-magnitude for scheduling; not a commitment.
| Phase | Duration | Notes |
|---|---|---|
| Foundation PR | ~1 week | i18next stack, ratchet baselines, empty en-AU namespaces, first i18next-cli status baseline |
| P0 sweep | ~6–10 weeks part-time | ~20 batches per §3.3; parallel feature work continues |
| P1 | ~2–3 weeks after P0 exit | Migration, OpenAPI regen, switcher, fr-FR bundle, review gates, Playwright switcher test |
| C7 | Parallel with P0 | Gates first non-English locale enable |
Appendix A — Carer-observation instruments (copyright)
Section titled “Appendix A — Carer-observation instruments (copyright)”Product default (2026-08-03): Abbey, PAINAD, Rockwood CFS, branded NRS/VAS, MMSE, Borg, etc. are design references only. Ship LynCareOS-original item lists and descriptors (Tier 2 lay review + i18n). Do not paste official validated instrument text into UI or locale JSON unless product explicitly opts into the Tier 3 verbatim exception (licence + official translations).
| Status | Examples | i18n / legal |
|---|---|---|
| Live UI today | Generic 0–10 pain bar; custom scale_1_5 / scale_1_10 observations | Tier 2 — our wording |
| Future modules | Observational distress, frailty snapshots (REQ-NVPAIN-01, REQ-FRAILTY-01) | LynCareOS-owned models — original copy; inspired-by noted in module spec |
| Verbatim instruments | Only if product requires official scale text | Tier 3 exception — not base product |
Agent rule: .cursor/rules/i18n-frontend.mdc.
Document history
Section titled “Document history”| Date | Version | Change |
|---|---|---|
| 2026-08-04 | 1.5 | I18N-P0 extraction complete (§3.3 batches 1–20); §4.6 amended for permanent ratchet exempts; P1 engineering started (V031 locale columns, /me effective locale, switcher + Account language section, formatLocale.ts). |
| 2026-08-03 | 1.4 | Foundation landed: react-i18next+i18next-icu, lib/i18n.ts (static en-AU, lazy non-default, REQ-I18N-03 sentinel, REQ-I18N-35 timeout, §3.4 detection stub), locales.config.json (REQ-I18N-05), typed keys (@types/i18next.d.ts), i18next.config.ts, ESLint i18n ratchets + check_i18n_eslint_ratchet.py. Verified: tsc -b, Vitest 482, i18next-cli status 0 keys. §1 status updated. |
| 2026-08-03 | 1.3 | §1.1 product decisions (no clinical toggle, hreflang in M1, marketing cookie, translate-on-demand, REINDEX ops done). §1.1 LynCareOS-owned observation instruments. Appendix A rewritten. Tooling: ESLint ratchets landed (foundation). |
| 2026-08-03 | 1.2 | Re-review: §4.4–4.6 quality gates/CI, test impact, renumbered exit; §5.1 OpenAPI regen, audit/tenant posture; §5.2 overlay D1 + visibility rule; §5.3 Intl/terminology; §5.5–5.6 renumber + service worker/deploy cache; §2 measurement caveat; §3.3 batch spine table; §3.4 mermaid resolution; §7 shopping catalog deferral; §9 knowledge alignment + doc 03 done rows; §10 effort estimate. |
| 2026-08-03 | 1.1 | Added §3.0 — translation is build-time, not runtime; contrast with the rejected real-time model; consequences for user content and for newly added strings. |
| 2026-08-03 | 1.0 | Initial design. Approach, tooling, detection chain, security boundary, and zero-cash translation model approved. |