Frontend i18n: enforce en/sv key parity with a test #60
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Severity: Low. From a frontend UX audit (positive finding + a gap).
Context
i18n discipline is good: no hardcoded user-facing English in JSX (all strings go through
t()), anden.json/sv.jsonare currently at exact parity. But there's no automated parity check —i18n.test.tsxhas no parity assertion, keys are untyped strings, and nothing fails CI ifsvdrifts fromen. The moment someone adds anenkey withoutsv, the Swedish UI silently falls back to English for that key.Suggested fix
Add a test asserting the flattened key sets of
en.jsonandsv.jsonare identical (and ideally that no value is empty). Optionally generate a typed key union so a missing translation is a type error.Source: frontend UX/design audit, 2026-06-06.
Done — merged to
main(4c24f03).Added
web/src/i18n/parity.test.ts(pure, no React) that runs in the normal Vitest suite, so en/sv drift fails locally and in CI:en.jsonandsv.jsonto dotted leaf keys (e.g.objects.columns.number) and asserts the sets are identical. On failure it lists exactly which keys are missing in sv and missing in en, so a drift is immediately actionable.Verified it's a true positive: injecting an en-only key + an empty value made both tests fail with the offending key names; the in-parity files pass (223 tests green; typecheck/lint clean; no codename).
Scope note: did not add a typed key union — the app uses template-literal keys (
t(\fields.types.${type}`),t(`authorities.${k}`),t(`visibility.${v}`)`, …) that strict key-typing would reject, so the runtime parity test is the friction-free guard the issue asked for. A typed-key approach (with template-key escape hatch) remains an optional follow-up.