Repository navigation
Closed
Task
12 / 1212 of 12 issues completed
Copy link
Labels
Description
Context
FloCafe's internationalization currently relies on a custom synchronous translation engine (frontend/src/lib/i18n.ts and frontend/src/hooks/useI18n.ts) with flat translation keys, bundled translation maps, regex-based ICU pluralization, and string-prefix locale matching.
This epic refactors FloCafe's frontend internationalization to use use-intl (the same runtime library standard in modern React/Next.js ecosystems) alongside our existing centralized language registry, active-locale lazy loading, atomic direction transitions, and strong repository-native CI validation.
Architectural Principles
- Decoupling of i18n, regional settings, and tax compliance: UI translation is strictly decoupled from business logic, tax compliance packs, and store currency/timezone configuration.
- Offline-first operation: Translations load locally from static JSON assets bundled with the desktop build. Zero network calls or external SaaS dependencies are introduced.
- Runtime library: Migrate to
use-intlv4. FloCafe is an Electron / Next.js static-export application and does not need Next.js locale routing, middleware, or server request localization.use-intlprovides ICU MessageFormat,useTranslations,createTranslator, type augmentation viaAppConfig, and client-sideIntlProviderintegration. - Centralized language registry:
frontend/src/lib/i18n/languages.tsis the single source of truth for supported UI languages, BCP-47 locale tags, native display names, text directions (ltr/rtl), user-facing selectability, and dynamic chunk loaders. - Active locale lazy loading with shared cache: Only the active locale bundle loads during initial startup. Additional locales load on demand via a shared loader/cache (
frontend/src/lib/i18n/loader.ts) that deduplicates in-flight requests and caches loaded messages for both React components and non-React consumers. - Atomic UI & direction transition: Active loaded language, messages,
<html lang>,<html dir>, and direction-dependent UI elements transition atomically once messages are ready, preventing document direction flipping ahead of message resolution or raw-key flashing. - English canonical schema & strict 100% leaf key parity:
frontend/src/lib/i18n/messages/en.jsondefines the canonical structure (namespaces, keys, ICU variable names). Every committed locale in the repository (including in-progressselectable: falselocales) must maintain 100% leaf key parity withen.jsonto prevent runtime fallback errors. - Nested message structure: Mechanical conversion from flat dotted keys (
"auth.signIn") to nested objects ("auth": { "signIn": ... }) required byuse-intl. - Strict type safety: Translation keys and locales are verified at compile time via
use-intlv4AppConfigmodule augmentation. Application domain mappings use exhaustively typed lookup objects (satisfies Record<DomainEnum, MessageKey>) instead of uncheckedRecord<string, string>maps or runtime string interpolation. - BCP-47 browser language matching: Browser language resolution parses BCP-47 language and regional tags via
Intl.Localeagainst selectable registered languages rather than brittle string prefix matching. - Strong repository-native CI validation: Local and CI checks (
npm run test:translations) enforce registry consistency, nested key parity, string leaf validity, ICU parse validation, and parameter/tag placeholder matching before merge. - Phased non-breaking migration: A backward-compatible bridge allows incremental component migration across PR-sized batches without breaking existing views. Only the final cleanup issue removes the legacy bridge.
- Language enablement vs. technical availability: A language can be implemented in the registry while remaining hidden from end users (
selectable: false). Persian (fa) technical migration is included here, but user-facing enablement remains governed by feat(i18n): add Persian/Farsi and Iran support #241. - No behavioral or wording changes: This epic is strictly an architectural refactoring. No translation copy, country profiles, tax configurations, or product defaults are modified.
Target Contributor Workflow
Adding a new language will follow this standardized workflow:
1. Add frontend/src/lib/i18n/messages/<lang>.json (copy en.json or run npm run i18n:add -- <lang>)
2. Add <lang> entry to frontend/src/lib/i18n/languages.ts
3. Translate leaf string values
4. Run npm run test:translations (or npm run i18n:check)
5. Test UI & RTL if applicable
6. Submit Pull Request
Sequencing
Phase 1 — Foundation & Safety (sequential)
#373 (Install use-intl & registry foundation)
↓
#374 (Convert flat messages to nested JSON)
↓
#382 (Repository-native validation & CI checks)
Phase 2 — Performance (sequential)
#375 (Lazy load active locale bundle with shared cache & atomic transitions)
Phase 3 — Component Migration (can run in parallel)
#376 (Batch 5A: shared, layout, auth, setup)
#377 (Batch 5B: POS & non-React print helper)
#378 (Batch 5C: orders, tables, customers, dashboard)
#379 (Batch 5D: KDS, Server App)
#380 (Batch 5E: settings, admin, products, remaining)
Phase 4 — Legacy Cleanup (after all of Phase 3)
#381 (Remove legacy custom i18n engine & hook)
Phase 5 — Contributor Ergonomics & Documentation (sequential)
#383 (Repo-native contributor & maintenance tooling)
↓
#384 (Git-native contributor documentation)
Sub-issues
- refactor(i18n): install use-intl and establish language registry/provider foundation #373 — refactor(i18n): install use-intl and establish language registry/provider foundation
- refactor(i18n): convert flat translation keys to nested message format #374 — refactor(i18n): convert flat translation keys to nested message format
- chore(i18n): add repository-native translation validation and integrity checks #382 — chore(i18n): add repository-native translation validation and integrity checks
- perf(i18n): lazy load active locale translation bundle #375 — perf(i18n): lazy load active locale translation bundle
- refactor(i18n): component migration 5A — shared, layout, auth, setup #376 — refactor(i18n): component migration 5A — shared, layout, auth, setup
- refactor(i18n): component migration 5B — POS #377 — refactor(i18n): component migration 5B — POS
- refactor(i18n): component migration 5C — orders, tables, customers, dashboard #378 — refactor(i18n): component migration 5C — orders, tables, customers, dashboard
- refactor(i18n): component migration 5D — KDS, Server App #379 — refactor(i18n): component migration 5D — KDS, Server App
- refactor(i18n): component migration 5E — settings, admin, remaining #380 — refactor(i18n): component migration 5E — settings, admin, remaining
- refactor(i18n): remove legacy custom i18n implementation #381 — refactor(i18n): remove legacy custom i18n implementation
- chore(i18n): add repo-native language contribution and maintenance tooling #383 — chore(i18n): add repo-native language contribution and maintenance tooling
- docs(i18n): contributor guide for adding new languages #384 — docs(i18n): contributor guide for adding new languages
Epic Acceptance Criteria
- All 4 current languages (
en,es,pt,fa) render and function identically to before. - RTL layout and bidirectional isolation (
<Ltr>,.rtl-flip,<html dir>) verified intact across all existing RTL test suites. - Only the active locale bundle is loaded during initial application boot.
- Language switching executes smoothly without raw-key flashing, layout unmounting, or direction desynchronization.
- Adding a new language requires only one message file and one registry entry in
languages.ts. - CI validation rejects missing keys, orphan keys, invalid ICU syntax, non-string leaves, and placeholder argument mismatches.
- All dynamic translation keys are replaced with exhaustively typed lookup mappings.
- Legacy custom
i18n.tsengine anduseI18nhook are completely removed after zero consumers remain. - Zero external translation network calls/dependencies; desktop app operates fully offline.
- Contributor guide accurately documents the offline Git-native contribution workflow.
Phase Progress Summary (All 5 Phases Complete)
- Phase 1 (Foundations & Validation) — refactor(i18n): install use-intl and establish language registry/provider foundation #373 (PR refactor(i18n): convert flat translation keys to nested message format #396), refactor(i18n): convert flat translation keys to nested message format #374 (PR chore(i18n): add repository-native translation validation and integrity checks #397), chore(i18n): add repository-native translation validation and integrity checks #382 (PR perf(i18n): lazy load active locale bundles with shared cache and atomic transitions #398)
- Phase 2 (Performance & Lazy Loading) — perf(i18n): lazy load active locale translation bundle #375 (PR refactor(i18n): migrate shared, auth, and setup components to use-intl #399)
- Phase 3 (Component Migration) — refactor(i18n): component migration 5A — shared, layout, auth, setup #376 (PR refactor(i18n): migrate shared, auth, and setup components to use-intl #399), refactor(i18n): component migration 5B — POS #377 (PR refactor(i18n): migrate POS components and web-print to use-intl #400), refactor(i18n): component migration 5C — orders, tables, customers, dashboard #378 (PR refactor(i18n): migrate orders, tables, customers, and dashboard to use-intl #401), refactor(i18n): component migration 5D — KDS, Server App #379 (PR refactor(i18n): migrate KDS and Server App components to use-intl #402), refactor(i18n): component migration 5E — settings, admin, remaining #380 (PR refactor(i18n): migrate settings, admin, catalog, and WhatsApp to use-intl #404)
- Phase 4 (Legacy Engine Cleanup) — refactor(i18n): remove legacy custom i18n implementation #381 (PR refactor(i18n): remove legacy custom i18n implementation and modularize utilities #410)
- Phase 5 (Tooling & Documentation) — chore(i18n): add repo-native language contribution and maintenance tooling #383 (PR fix(i18n): enable Persian, resolve scoped translation keys, and add repo-native translation tooling #412), docs(i18n): contributor guide for adding new languages #384 (PR docs(i18n): add comprehensive contributor guide for internationalization #413)
Sub-issues
Collapse Sub-issuesSub-issues
Loading 12 sub-issues
Activity
[-]refactor(i18n): migrate to use-intl architecture[/-][+]refactor(i18n): migrate to scalable use-intl architecture[/+]khaira777 commentedon Aug 19, 2026
Progress update — Phase 1:
9e32613):use-intlv4 installed, centralized language registry,I18nProvidermounted,AppConfigaugmentation, and the backward-compatible bridget()adapter now traverses the nested tree, and the translation/e2e tests were updated for the nested schema. The no-mistakes pipeline is running (review passed, tests in progress); PR pending.khaira777 commentedon Aug 19, 2026
Progress update — Phase 1 complete 🎉
9e32613)9236866)Phase 1 (foundation → nested → validation gate) is now functionally complete. #382's validation suite is the safety gate that protects all subsequent component migration PRs (#375–#384):
selectable: falsefa)@formatjs/icu-messageformat-parser)It already caught a real
es.jsonplural bug and a pre-existing 3+ segment key coverage gap. Full detail on #382.Phase 2 onwards (ready to kick off once #382 merges): #375 (lazy load) → #376–#380 (component migration, parallel) → #381 (remove legacy engine) → #383 → #384 (tooling/docs).
khaira777 commentedon Aug 19, 2026
✅ Phase 1 complete — all three sub-issues merged & closed
9e32613· closed9236866· closed588cc8c· closedPhase 1 = foundation → nested structure → safety gate, all shipped. The #382 validation suite is now the enforced gate protecting every subsequent migration PR and community translation contribution (registry↔file consistency, en-canonical leaf parity, string leaf validity, ICU syntax, placeholder/selector + rich-text tag parity, TS key safety, fa fallback safeguards, negative fixture tests). It's wired into
npm testand exposed asnpm run i18n:check.Next up (Phase 2):
use-intlhooks (parallelizable)i18n.tsengineCarried-forward notes from #373 (deferred):
getBrowserLanguage()→ BCP-47Intl.Localematching.HtmlLangSync/KdsHtmlLang→ usegetLanguageLocale()instead of hard-coded tags.khaira777 commentedon Aug 19, 2026
✅ Phase 2 complete — #375 merged & closed
8df666a· closedPhase 2 = lazy locale loading, shipped. Only the active locale bundle is fetched at startup — every static-export page now eagerly loads just packaged English (95 KB); es/pt/fa (~357 KB) are on-demand chunks (~79% startup translation payload reduction).
I18nProviderresolves the initial language deterministically (store → browser match → English), protects against race conditions from rapid switching, reverts gracefully on failure, and transitions messages +<html lang>/<html dir>atomically. A new build-output test (test:locale-chunks) enforces the lazy-chunk + offline invariants.Next up (Phase 3 — component migration, parallelizable):
Then #381 (remove legacy engine) → #383/#384 (tooling/docs).
Carried-forward notes (unchanged from #373):
getBrowserLanguage()→ BCP-47Intl.Localematching.HtmlLangSync/KdsHtmlLang→ usegetLanguageLocale()instead of hard-coded tags. (perf(i18n): lazy load active locale translation bundle #375 already moved these togetLanguageLocale()for the atomic lang/dir sync — item 2 is effectively resolved.)khaira777 commentedon Aug 19, 2026
All 12 sub-issues (#373 through #384) and all 5 phases across Epic #372 have landed in main:
FloCafe internationalization is 100% offline-first, Git-native, and fully modernized.