Skip to content

feat(countries): localize country display names using active UI locale #392

Closed

Description

@khaira777

Refs: #388
Depends on: #373 (merged)

Context

FloCafe supports multi-language UI localization across English (en), Spanish (es), Portuguese (pt), and Persian (fa). However, country selectors in Setup and Settings currently display hardcoded English country names regardless of the active UI language.

Verified Current Behavior

  • Static Country Names (main/countries.ts lines 38, 103, 339):
    const dn = new Intl.DisplayNames(['en'], { type: 'region' });
    Country names in COUNTRIES are generated statically with English region names (dn.of(code)).
  • Frontend Export (frontend/src/lib/countries.ts): Re-exports countryName(code) from backend countries.ts, which unconditionally returns English strings.
  • Consumer Interfaces (frontend/src/app/setup/page.tsx and frontend/src/app/(dashboard)/settings/page.tsx): Render countryName(c.code), always presenting English text to Spanish, Portuguese, or Persian users.

Problem

When the user selects Spanish, Portuguese, or Persian as their interface language, country names in Setup and Settings (e.g. "Germany", "United States", "Spain", "Brazil") remain in English instead of "Alemania", "Estados Unidos", "España", "Brasil", or Persian equivalents.

Architectural Decision

  • Persisted Country Identity: Remains strictly the ISO 3166-1 alpha-2 code (CA, BR, DE, IR, US, etc.). Never store translated country names in the database, settings, or API contracts.
  • Presentation-Only Localization: Derive localized display names using native runtime Intl.DisplayNames([activeUiLocale], { type: 'region' }) with a fallback to the static English name or ISO code.
  • No JSON Translation Bloat: Do NOT copy hundreds of country names into message catalog files (en.json, es.json, pt.json, fa.json). Native Intl.DisplayNames provides standards-compliant, localized region names offline.
  • List Sorting: Sort displayed country lists based on the derived localized name in the active locale (while retaining pinned top items like IN and AR), not the English names.
  • Search Matching: Ensure country query filtering matches localized display names, English names, ISO codes, and currencies.

Exact Implementation Scope

  1. Frontend Localization Helper (frontend/src/lib/countries.ts / hook or utility):
    • Provide a helper (e.g. getLocalizedCountryName(code: string, locale: string): string) that creates/caches an Intl.DisplayNames([locale], { type: 'region' }) instance and resolves the localized name for a given ISO code.
  2. Setup Country Selector (frontend/src/app/setup/page.tsx):
    • Render localized country names based on the active wizard language.
    • Re-sort filtered country options by their localized names when the active language changes.
    • Support searching by localized country names.
  3. Settings Country Selector (frontend/src/app/(dashboard)/settings/page.tsx):
    • Render localized country names based on current UI language.
    • Sort options using localized names.

Required Behavior

  • For UI language es: DE displays as "Alemania", US as "Estados Unidos", JP as "Japón".
  • For UI language pt: DE displays as "Alemanha", US as "Estados Unidos", JP as "Japão".
  • For UI language fa: DE displays as "آلمان", US as "ایالات متحده".
  • For UI language en: Displays in English.
  • Changing UI language immediately re-renders all country display names in the active language without page reload.
  • Persisted tenant country setting remains the ISO alpha-2 code.

Backward Compatibility / Upgrade Behavior

  • Completely non-breaking. Canonical data models and backend APIs continue to receive and store ISO codes.

Offline-First Requirements

  • 100% offline. Intl.DisplayNames is built into modern JavaScript runtimes (V8/Node/Electron/browsers). Zero network requests.

Non-Goals / What NOT to Do

  • Do NOT populate message JSON files with manual country translations.
  • Do NOT sort using English strings while rendering localized labels.
  • Do NOT modify backend ISO code storage or tax pack country matching.
  • Do NOT add third-party country localization libraries.

Acceptance Criteria

  • Country selectors in Setup and Settings dynamically render country names in the active UI locale.
  • Country list sorting respects localized alphabetical order.
  • Country search matches localized names, ISO codes, and currencies.
  • Changing UI language updates country names dynamically.
  • ISO alpha-2 codes remain the persisted tenant country value.
  • Completely functional offline with zero network calls.

Verification

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

Dependencies

Relationship to Epic

Activity

  1. added
    enhancement
    area:frontend
    on Aug 18, 2026
  2. khaira777 commented on Aug 20, 2026

    @khaira777
    ContributorAuthor

    Status update — 2026-08-20

    ⏳ Ready to start; not started. Dependency #373 is merged. There is currently no implementation branch, PR, or no-mistakes pipeline run for this issue.

  3. khaira777 commented on Aug 20, 2026

    @khaira777
    ContributorAuthor

    Status update — 2026-08-20

    🔄 Implementation complete; validation in progress. Commit e624e729 remains intact. The no-mistakes run 01M0GQR716R7VQGW1S7E2MESWM has completed rebase, review, and tests; documentation is currently running on pipeline head b4981eb1.

    No PR has been opened yet. Next stages are lint, push, PR creation, and CI.

  4. khaira777 commented on Aug 21, 2026

    @khaira777
    ContributorAuthor

    Completed — PR #435 merged

    Issue #392 is complete. PR #435 merged into main at edb980ad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:frontendenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions