Skip to content

refactor(i18n): remove legacy custom i18n implementation #381

Closed

Description

@khaira777

Refs: #372
Depends on: #376, #377, #378, #379, #380

Context

All 5 component migration batches (#376–#380) are now complete, and every view in frontend/src has migrated to useTranslations(), createTranslator, and the central language registry.

This issue is the sole owner of legacy removal. It eliminates the legacy custom translation engine, the old useI18n() hook, the regex ICU plural parser, and the temporary compatibility bridge, leaving a clean, modular architecture.

What to do

1. Reorganize Surviving Utilities into Focused Modules

Move surviving non-legacy utilities into clear, dedicated modules:

  • Browser Language Detection -> frontend/src/lib/i18n/browser-language.ts:
    BCP-47 parsing and matching via Intl.Locale against registered selectable languages:
    import { LANGUAGES, type Language } from './languages';
    
    export function getBrowserLanguage(): Language {
      if (typeof navigator === 'undefined' || !navigator.languages?.length) return 'en';
      for (const raw of navigator.languages) {
        try {
          const parsed = new Intl.Locale(raw);
          for (const [code, config] of Object.entries(LANGUAGES)) {
            if (!config.selectable) continue;
            const regLocale = new Intl.Locale(config.locale);
            if (parsed.language === regLocale.language) {
              return code as Language;
            }
          }
        } catch {
          // Continue on invalid locale tag
        }
      }
      return 'en';
    }
  • Server Language Synchronization -> frontend/src/lib/i18n/server-language.ts:
    Contains fetchServerInfo and useSyncServerLanguage for standalone KDS and Server App language sync.
  • Domain Enum Mappings -> frontend/src/lib/i18n/enums.ts (or i18n-enums.ts):
    Exhaustively typed mappings from backend status strings to translation keys.
  • Shared Loader & Cache -> frontend/src/lib/i18n/loader.ts:
    Shared message loader, in-flight promise deduplication, and in-memory cache.

2. Remove Legacy Files & Artifacts

  • Delete frontend/src/hooks/useI18n.ts.
  • Remove legacy implementations from frontend/src/lib/i18n.ts:
    • Delete old synchronous t(key, lang, params) function.
    • Delete formatIcuPlural regex parser and plural rules cache.
    • Delete static translation map and compatibility wrapper.
  • Either remove frontend/src/lib/i18n.ts entirely or keep it purely as a clean re-export barrel for the modular i18n subsystem.

3. Add CI Guardrail Against Legacy Regressions

Update tests/translations.test.ts to assert that:

  • No file in frontend/src/ imports or references useI18n.
  • No file in frontend/src/ references the removed custom formatIcuPlural.
  • No unchecked dynamic translation calls exist.

What NOT to do

  • Do NOT modify translation JSON files in frontend/src/lib/i18n/messages/.
  • Do NOT touch I18nProvider.tsx or the language registry in languages.ts.
  • Do NOT delete server-language.ts or break KDS language synchronization.

Acceptance Criteria

  • frontend/src/hooks/useI18n.ts is deleted.
  • Legacy custom t(), regex plural formatter, and compatibility wrapper removed.
  • Surviving utilities modularized into browser-language.ts, server-language.ts, and loader.ts.
  • BCP-47 browser language matching is robust against regional and script subtags.
  • Zero references to useI18n remain in the codebase.
  • All standard checks and full test suites pass.

Verification

# Verify zero legacy callers
grep -r "useI18n" frontend/src/           # must return 0 results
grep -r "formatIcuPlural" frontend/src/   # must return 0 results

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

Activity

  1. added
    enhancement
    area:frontend
    on Aug 17, 2026
  2. self-assigned this
    on Aug 19, 2026
  3. khaira777 commented on Aug 19, 2026

    @khaira777
    ContributorAuthor

    Completed by #410 (merged into main at commit 64f6076). All legacy hooks, custom engines, and formatters have been removed, surviving utilities modularized, and CI guardrails verified.

  4. added a commit that references this issue on Aug 23, 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