Skip to content

refactor(i18n): convert flat translation keys to nested message format #374

Closed

Description

@khaira777

Refs: #372
Depends on: #373

Context

use-intl expects nested JSON objects representing namespaces (e.g. useTranslations('auth') accessing key signIn). FloCafe's current translation files contain 2,053 flat dotted keys ("auth.signIn": "Sign In").

This issue performs a purely mechanical, deterministic data transformation from flat dot-notation to nested JSON objects across all 4 locale files.

Current State

4 translation files in frontend/src/lib/i18n/messages/ with 2,053 flat keys each:

  • en.json (canonical schema)
  • es.json
  • pt.json
  • fa.json

What to do

1. Collision Detection & Resolution

Before conversion, run an automated check to verify that no key path conflicts with an ancestor object (for example, having both "a": "..." and "a.b": "..." would cause a collision in a nested structure). If any collision exists, document and resolve it explicitly.

2. Deterministic Nesting Conversion

Convert all 4 JSON files mechanically:

Before (flat):

{
  "auth.email": "Email",
  "auth.signIn": "Sign In",
  "orders.pending": "Pending",
  "orders.preparing": "Preparing"
}

After (nested):

{
  "auth": {
    "email": "Email",
    "signIn": "Sign In"
  },
  "orders": {
    "pending": "Pending",
    "preparing": "Preparing"
  }
}

3. Update Compatibility Adapter

Update t(key, lang, params) in frontend/src/lib/i18n.ts to resolve dotted paths by traversing nested message objects (e.g. key.split('.').reduce(...)), ensuring legacy callers passing "auth.signIn" continue to receive expected strings.

4. Update Equivalence & Translation Tests

Update tests/translations.test.ts to recursively traverse nested leaf nodes when validating key parity across en, es, pt, and fa. Ensure equivalence tests verify that every old dotted key resolves to the exact same value in the new nested structure.

What NOT to do

  • Do NOT change any translation wording or copy.
  • Do NOT add new translation keys or delete existing ones.
  • Do NOT introduce ICU features (select, rich text) during this data conversion.
  • Do NOT migrate components from useI18n to useTranslations.
  • Do NOT remove the compatibility adapter.
  • Do NOT keep duplicate flat files around permanently.

Acceptance Criteria

  • All 4 message files in frontend/src/lib/i18n/messages/ converted to valid nested JSON.
  • 100% leaf key parity maintained across all locales (exact count and values preserved).
  • Compatibility adapter in i18n.ts resolves dotted paths against nested message objects.
  • tests/translations.test.ts updated and passing with nested message schema.

Verification

npm run test:translations
npm run lint
npm run build:frontend
npm test

Activity

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

    @khaira777
    ContributorAuthor

    Implemented, stacked on #373. The no-mistakes pipeline is running (--yes auto-fix; review already passed with 0 findings, i18n tests in progress) and will create the PR automatically.

    What landed:

    • Converted all 4 locale files (en/es/pt/fa) from flat dotted keys to nested JSON — 2,053 leaves each, round-trip verified (no value or key changes).
    • Ran collision detection first: no ancestor/descendant key conflicts (max depth 4, no anomalous keys) in any locale.
    • Updated t() in frontend/src/lib/i18n.ts to resolve dotted keys by traversing the nested message tree (target language → English → raw-key fallback), so every legacy t('auth.signIn') caller keeps working.
    • Updated tests/translations.test.ts to flatten nested leaves for parity/validation and scope duplicate-key detection per object.
    • Updated tests/e2e-argentina-flow.test.ts key extractor for nested JSON.

    Notes:

    Leaving this issue open for review/merge.

  3. self-assigned this
    on Aug 19, 2026
  4. added theissue type on Aug 19, 2026
  5. khaira777 commented on Aug 19, 2026

    @khaira777
    ContributorAuthor

    ✅ Done — merged as 9236866 via PR #396

    Flat → nested message conversion complete across en, es, pt, fa (2,053 leaves each, 26 namespaces, max depth 4; round-trip verified, no wording/key changes, no collisions).

    • i18n.ts t() resolves dotted keys via resolveMessage() traversal (target lang → English → raw-key fallback).
    • tests/translations.test.ts updated with flattenLeaves() parity + scoped findDuplicateKeys().
    • tests/e2e-argentina-flow.test.ts extractJsonKeys() now recursive over nested JSON.

    This unblocked #382 (the validation gate), which merged next. Closing.

  6. khaira777 commented on Aug 19, 2026

    @khaira777
    ContributorAuthor

    Closed as completed.

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

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions