1.9 KiB
1.9 KiB
Shared i18n architecture (frontend + backend)
Scope
Issue #175 requires one shared i18n contract for MVP host/player flows across frontend and backend.
Source of truth
- Catalog:
shared/i18n/lobby.json - Locales:
- supported:
en,da - default/fallback:
en
- supported:
Both Angular (frontend/angular/src/app/lobby-i18n.ts) and Django (lobby/i18n.py) read from this catalog.
Key naming convention
- Domain-first namespaces:
frontend.ui.common.*frontend.ui.host.*frontend.ui.player.*frontend.errors.*backend.errors.*backend.error_codes.*
- UI lookup keys in Angular are shortened aliases mapped under
frontend.ui, e.g.:host.start_roundplayer.submit_guesscommon.session_code
- Backend API errors return stable code + localized message:
error_code= machine-stable key frombackend.error_codeserror= localized message frombackend.errorslocale= resolved request locale
Fallback model (robust)
- Resolve requested locale (
Accept-Languageon backend, user/browser preference on frontend). - If locale unsupported -> use default
en. - If key missing -> return key and log warning.
- If locale translation missing for key -> fallback to
entranslation.
Audio-routing policy
- Catalog capability:
frontend.capabilities.client_has_no_audio_output = true - Host/player clients expose this as a read-only capability flag.
- Policy: phone clients must not play audio directly; only primary/host output is allowed.
Verification
- Backend tests:
lobby/tests.pyi18n coverage for locale selection + fallback + error-code/message matrix. - Frontend smoke/e2e-level unit coverage:
frontend/angular/src/app/lobby-i18n.spec.tsfrontend/angular/src/app/i18n-mvp-flow-smoke.spec.tsfrontend/angular/src/app/features/host/host-shell.component.spec.tsfrontend/angular/src/app/features/player/player-shell.component.spec.ts