Skip to content

refactor(i18n): component migration 5A — shared, layout, auth, setup #376

Closed

Description

@khaira777

Refs: #372
Depends on: #375
Can parallel with: #377, #378, #379, #380

Context

This is the first of 5 component migration batches. Migrate shared layout components, confirmation dialogs, authentication pages, and the initial setup wizard from the legacy useI18n() hook to useTranslations() from use-intl.

Global Component Migration Rules

  • Use const t = useTranslations('namespace') from use-intl.
  • Access leaf keys directly: t('signIn') instead of t('auth.signIn').
  • Use compile-time type-safe keys verified against AppConfig.
  • Eliminate template-literal dynamic key construction; use exhaustively typed lookup mappings.
  • Do NOT remove the compatibility adapter or legacy hook in this PR. Issue refactor(i18n): remove legacy custom i18n implementation #381 owns final removal after all 5 batches are complete.
  • Do NOT alter translation wording, layout structure, or product behavior.

Files to Migrate (12 files)

Layout & Shared Components (9 files)

  • frontend/src/components/layout/AuthGuard.tsx
  • frontend/src/components/layout/Sidebar.tsx
  • frontend/src/components/layout/StatusBar.tsx
  • frontend/src/components/layout/GlobalNotifications.tsx
  • frontend/src/components/layout/MenuActionHandler.tsx
  • frontend/src/components/layout/UpdateBadge.tsx
  • frontend/src/components/layout/HtmlLangSync.tsx (uses active loaded direction from i18n context)
  • frontend/src/components/layout/DirectionalToaster.tsx (uses active loaded direction from i18n context)
  • frontend/src/hooks/use-confirm.tsx (confirmation dialog hook)

Authentication Pages (2 files)

  • frontend/src/app/auth/login/page.tsx
  • frontend/src/app/auth/recover/page.tsx

Initial Setup Wizard (1 file)

  • frontend/src/app/setup/page.tsx

Dynamic Key Handling in setup/page.tsx

setup/page.tsx currently constructs dynamic keys for setup profiles and service models (e.g. t(setup.${item.value}Label), t(setup.${item.value}Desc), t(setup.${item.value}Details)).

Replace with exhaustively typed mapping objects:

type SetupProfile = 'empty' | 'express' | 'demo';

const SETUP_PROFILE_KEYS = {
  empty: { label: 'emptyLabel', desc: 'emptyDesc', details: 'emptyDetails' },
  express: { label: 'expressLabel', desc: 'expressDesc', details: 'expressDetails' },
  demo: { label: 'demoLabel', desc: 'demoDesc', details: 'demoDetails' },
} as const satisfies Record<SetupProfile, { label: string; desc: string; details: string }>;

type ServiceModel = 'qsr' | 'finedine';

const SERVICE_MODEL_KEYS = {
  qsr: { label: 'qsrLabel', desc: 'qsrDesc', details: 'qsrDetails' },
  finedine: { label: 'finedineLabel', desc: 'finedineDesc', details: 'finedineDetails' },
} as const satisfies Record<ServiceModel, { label: string; desc: string; details: string }>;

Also update language selector options in setup/page.tsx to derive selectable languages from the central LANGUAGES registry (frontend/src/lib/i18n/languages.ts) rather than hardcoded language arrays.

What NOT to do

  • Do NOT remove frontend/src/hooks/useI18n.ts or the compatibility bridge in frontend/src/lib/i18n.ts.
  • Do NOT change any translation strings or keys.
  • Do NOT rewrite ICU plural rules.
  • Do NOT modify setup logic or API payloads.

Acceptance Criteria

  • All 12 files in scope migrated to useTranslations() / registry helpers.
  • No unchecked template-literal translation calls remain in these files.
  • Language selection in setup wizard derives from LANGUAGES registry (selectable: true).
  • HtmlLangSync and DirectionalToaster synchronize with active loaded locale state.
  • Backward-compatibility layer remains untouched and operational for unmigrated batches.
  • Auth, setup, and layout RTL behavior verified unchanged.

Verification

npm run lint
npm run build:frontend
npm test
npm run test:rtl-setup-auth-settings
npm run test:first-run
npm run test:auth-ui-deterministic

Activity

  1. added
    enhancement
    area:frontend
    on Aug 17, 2026
  2. khaira777 commented on Aug 19, 2026

    @khaira777
    ContributorAuthor

    Folded-in carried-forward item (from #373, Phase 2 handoff): getBrowserLanguage() in frontend/src/lib/i18n.ts still uses string-prefix matching. Update it to parse navigator.language via Intl.Locale and match the language subtag against the LANGUAGES registry (selectable languages). setup/page.tsx is in both scopes, so it fits naturally here.

  3. khaira777 commented on Aug 19, 2026

    @khaira777
    ContributorAuthor

    Status: implementation complete, pipeline running

    What was done (Phase 3 batch 5A — 12 files):

    • Layout/shared: AuthGuard, Sidebar, StatusBar, GlobalNotifications, MenuActionHandler, UpdateBadge, HtmlLangSync, DirectionalToaster, use-confirm — all migrated from useI18n() to useTranslations('namespace') with namespace-scoped leaf keys.
    • Auth: auth/login, auth/recover migrated; the tenant picker now uses typed leaf-key maps for backend role/business-type enums (mirrors of i18n-enums for the use-intl namespace scope).
    • Setup wizard: migrated to useTranslations('setup'); profile/service-model cards use exhaustively typed key mappings (SETUP_PROFILE_KEYS / SERVICE_MODEL_KEYS) — no template-literal dynamic keys remain; the language selector now derives options from the central LANGUAGES registry (selectable: true), and the wizard's language follows the shared store so the atomic provider renders it immediately (the perf(i18n): lazy load active locale translation bundle #375 manual loadedLanguage gate is gone).
    • Context-driven direction (perf(i18n): lazy load active locale translation bundle #375 follow-up): HtmlLangSync and DirectionalToaster now read the active loaded locale from the i18n context (useLocale() + registry reverse lookup) instead of the store request — document lang/dir and toast placement only flip after the locale bundle has actually loaded. This also fixes the toaster briefly following the store during a switch.
    • BCP-47 fold-in: getBrowserLanguage() now parses navigator.language with Intl.Locale and matches the language subtag against the registry (replaces string-prefix matching). Behavior preserved: fa-IR/fa/fa-AF → fa, es-ES → es, pt-BR → pt, en-US → en, unsupported/absent → en.

    Untouched by design: legacy bridge (lib/i18n.ts) and useI18n hook remain operational for unmigrated batches — #381 owns their removal.

    Verification: lint 0 errors; frontend typecheck, backend build, and static export pass; all focused suites pass (test:rtl-setup-auth-settings, test:rtl-dashboard-pos-common, test:rtl-kds-server-whatsapp, test:translations, test:locale-chunks, test:first-run, test:auth-ui-deterministic); full npm test green. RTL evidence tests now wrap the context-driven components in IntlProvider.

    Note: local full-suite runs occasionally hit pre-existing flaky backend suites (kds-contract, bills-print-api) — they fail with varying assertions on unmodified main too and pass on retry; CI results are the source of truth.

  4. khaira777 commented on Aug 19, 2026

    @khaira777
    ContributorAuthor

    ✅ Done — merged

    Acceptance criteria — all met:

    • All 12 files migrated to useTranslations() / registry helpers
    • No unchecked template-literal translation calls remain in these files (typed key mappings SETUP_PROFILE_KEYS / SERVICE_MODEL_KEYS, typed nav labelKeys)
    • Setup language selector derives from LANGUAGES registry (selectable: true), with Persian offered browser-relative for fa users (existing e2e contract, feat(i18n): add Persian/Farsi and Iran support #241)
    • HtmlLangSync and DirectionalToaster synchronize with the active loaded locale from the i18n context (useLocale + registry reverse lookup) — lang/dir and toast placement only flip after the bundle loads
    • Backward-compatibility layer (legacy bridge + useI18n) untouched and operational — refactor(i18n): remove legacy custom i18n implementation #381 owns removal
    • Auth, setup, and layout RTL behavior verified (unit + e2e)

    Also folded in (deferred BCP-47 item): getBrowserLanguage() now parses navigator.language with Intl.Locale and matches the language subtag against the registry (replaces string-prefix matching). Behavior preserved for all tested locales.

    Verification: lint clean; frontend typecheck, backend build, static export pass; focused suites green (test:rtl-setup-auth-settings, test:rtl-dashboard-pos-common, test:rtl-kds-server-whatsapp, test:translations, test:locale-chunks, test:first-run, test:auth-ui-deterministic); full npm test green; full Playwright e2e green in CI (including the setup fa-browser and settings-RTL specs).

    Notes for the next batch:

    • The provider's resolveInitialLanguage now honors a fa browser locale (and reads the persisted language directly), consistent with the e2e contract.
    • The setup wizard's language follows the shared store; the perf(i18n): lazy load active locale translation bundle #375 manual loadedLanguage gate was removed as redundant.
  5. self-assigned this
    on Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:frontendenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions