Repository navigation
Description
Refs: #372
Depends on: None
Context
FloCafe currently uses a hand-rolled translation helper in frontend/src/lib/i18n.ts with 4 static JSON imports, synchronous t(key, lang, params), and no compile-time type checking.
This issue establishes the use-intl v4 foundation, centralizes language metadata into a single registry, sets up the I18nProvider, and enables TypeScript AppConfig module augmentation based on the official use-intl v4 specification.
No components are migrated in this issue. All existing consumers continue working through a backward-compatible adapter in frontend/src/lib/i18n.ts. Lazy loading is deliberately reserved for #375; this issue provides a synchronous compatibility baseline.
Architectural Decisions Relevant to This Issue
- Library:
use-intlv4 (React 19 & Next.js static export compatible). - Central Language Registry with Inferred Types: Define
LANGUAGESusingas const satisfies Record<string, LanguageConfig>. DeriveLanguageaskeyof typeof LANGUAGESandLocalefrom(typeof LANGUAGES)[Language]['locale']rather than maintaining duplicate union types. - use-intl v4 AppConfig Augmentation: Augment
use-intl'sAppConfiginterface inmessages.d.ts(not legacy globalIntlMessages). - Synchronous Compatibility Baseline: In this phase, the provider and compatibility adapter maintain synchronous access to bundled messages so existing views operate without asynchronous bootstrap flicker. Lazy loading is introduced in perf(i18n): lazy load active locale translation bundle #375.
- Persian (feat(i18n): add Persian/Farsi and Iran support #241) Status: Configured with
direction: 'rtl'andselectable: falseto maintain technical readiness without bypassing feat(i18n): add Persian/Farsi and Iran support #241 user-facing enablement.
What to do
1. Install use-intl
Install use-intl in the frontend:
cd frontend && npm install use-intl2. Create Centralized Language Registry
Create frontend/src/lib/i18n/languages.ts:
import en from './messages/en.json';
import es from './messages/es.json';
import pt from './messages/pt.json';
import fa from './messages/fa.json';
export type LanguageDirection = 'ltr' | 'rtl';
export interface LanguageConfig {
readonly locale: string;
readonly nativeName: string;
readonly direction: LanguageDirection;
readonly selectable: boolean;
readonly messages: Record<string, unknown>;
readonly load?: () => Promise<{ default: Record<string, unknown> }>;
}
export const LANGUAGES = {
en: {
locale: 'en',
nativeName: 'English',
direction: 'ltr',
selectable: true,
messages: en,
load: () => import('./messages/en.json'),
},
es: {
locale: 'es',
nativeName: 'Español',
direction: 'ltr',
selectable: true,
messages: es,
load: () => import('./messages/es.json'),
},
pt: {
locale: 'pt-BR',
nativeName: 'Português',
direction: 'ltr',
selectable: true,
messages: pt,
load: () => import('./messages/pt.json'),
},
fa: {
locale: 'fa-IR',
nativeName: 'فارسی',
direction: 'rtl',
selectable: false, // Governed by #241 acceptance
messages: fa,
load: () => import('./messages/fa.json'),
},
} as const satisfies Record<string, LanguageConfig>;
export type Language = keyof typeof LANGUAGES;
export type Locale = (typeof LANGUAGES)[Language]['locale'];
export function getLanguageDirection(lang: Language): LanguageDirection {
return LANGUAGES[lang]?.direction ?? 'ltr';
}
export function getLanguageLocale(lang: Language): string {
return LANGUAGES[lang]?.locale ?? 'en';
}3. Move Message Files
Move frontend/src/lib/i18n/{en,es,pt,fa}.json to frontend/src/lib/i18n/messages/{en,es,pt,fa}.json.
4. Create I18nProvider
Create frontend/src/components/providers/I18nProvider.tsx:
'use client';
import { type ReactNode } from 'react';
import { IntlProvider } from 'use-intl';
import { usePosSettingsStore } from '@/store/pos-settings';
import { LANGUAGES, type Language } from '@/lib/i18n/languages';
export function I18nProvider({ children }: { children: ReactNode }) {
const language = usePosSettingsStore((s) => s.language) as Language;
const config = LANGUAGES[language] ?? LANGUAGES.en;
return (
<IntlProvider locale={config.locale} messages={config.messages}>
{children}
</IntlProvider>
);
}Mount I18nProvider in frontend/src/app/layout.tsx wrapping the root content and client layout components.
5. Establish use-intl v4 AppConfig Augmentation
Create frontend/src/lib/i18n/messages.d.ts using en.json and registered BCP-47 locales:
import type en from './messages/en.json';
import type { Locale } from './languages';
type Messages = typeof en;
declare module 'use-intl' {
interface AppConfig {
Messages: Messages;
Locale: Locale;
}
}6. Maintain Backward-Compatible Bridge in i18n.ts
Update frontend/src/lib/i18n.ts to import Language, LanguageDirection, and direction helpers from ./i18n/languages. Re-export them so existing callers (HtmlLangSync, DirectionalToaster, useI18n, etc.) remain fully functional.
What NOT to do
- Do NOT implement asynchronous lazy loading in this PR (reserved for perf(i18n): lazy load active locale translation bundle #375).
- Do NOT convert flat keys to nested objects (reserved for refactor(i18n): convert flat translation keys to nested message format #374).
- Do NOT migrate components from
useI18ntouseTranslations(reserved for refactor(i18n): component migration 5A — shared, layout, auth, setup #376–refactor(i18n): component migration 5E — settings, admin, remaining #380). - Do NOT remove legacy
t()oruseI18n()(reserved for refactor(i18n): remove legacy custom i18n implementation #381). - Do NOT change any translation content or wording.
- Do NOT enable Persian for end-user selection.
Acceptance Criteria
-
use-intlv4 installed infrontend/package.json. - Central language registry created at
frontend/src/lib/i18n/languages.tswithas const satisfiestyping and derivedLanguage/Localetypes. - Translation JSON files relocated to
frontend/src/lib/i18n/messages/. -
I18nProvidercreated and mounted infrontend/src/app/layout.tsx. - Official
use-intlAppConfigmodule augmentation active infrontend/src/lib/i18n/messages.d.ts. - Full backward compatibility maintained for existing
useI18n()andt()callers. - No blank screen or asynchronous loading artifacts introduced.
Verification
npm run lint
npm run build:frontend
npm test
npm run test:translations
Activity
[-]refactor(i18n): install use-intl, add language registry and IntlProvider[/-][+]refactor(i18n): install use-intl and establish language registry/provider foundation[/+]khaira777 commentedon Aug 19, 2026
Implemented in PR #395: #395
What landed:
use-intlv4 (^4.13.7) in the frontend.frontend/src/lib/i18n/languages.ts) usingas const satisfies Record<string, LanguageConfig>with derivedLanguage/Localetypes.frontend/src/lib/i18n/messages/.AppConfigmodule augmentation (messages.d.ts) — confirmed active, not silently falling back toRecord<string, any>.I18nProviderin the root layout.t()/useI18n()consumer via backward-compatible re-exports ini18n.ts.tests/translations.test.tsandtests/e2e-argentina-flow.test.tsfor the newmessages/path.Verification: frontend build (static export + full TypeScript check) ✅, frontend lint ✅,
npm run test:translations✅, and the no-mistakes pipeline passed with zero findings (CI green).Leaving this issue open for review/merge. Next dependency in the epic is #374 (flat → nested message conversion).
Noted (out of scope for #373, left for later phases):
getBrowserLanguage()still uses string-prefix matching; the epic wants BCP-47Intl.Localematching.HtmlLangSync/KdsHtmlLangstill hard-code locale tags.refactor(i18n): install use-intl and establish language registry/prov…
khaira777 commentedon Aug 19, 2026
✅ Done — merged as
9e32613via PR #395Foundation complete:
use-intl@^4.13.7installed infrontend/.frontend/src/lib/i18n/languages.ts— central language registry (as const satisfies Record<string, LanguageConfig>; derivedLanguage/Locale; Persianselectable:false).frontend/src/lib/i18n/messages.d.ts—use-intlv4AppConfigaugmentation (verified live).frontend/src/components/providers/I18nProvider.tsxmounted inlayout.tsx.frontend/src/lib/i18n/messages/;i18n.tsre-exports registry as backward-compatible bridge.translations.test.ts,e2e-argentina-flow.test.ts).Deferred to later phases (recorded here so they aren't lost):
getBrowserLanguage()still uses string-prefix matching; epic wants BCP-47Intl.Localematching.HtmlLangSync/KdsHtmlLanghard-code locale tags (fa-IR/es/pt-BR/en); should usegetLanguageLocale().Closing.
khaira777 commentedon Aug 19, 2026
Closed as completed.