Skip to content

chore(i18n): add repository-native translation validation and integrity checks #382

Closed

Description

@khaira777

Refs: #372
Depends on: #374

Context

FloCafe manages translations directly within the Git repository without any SaaS translation management platform (no Crowdin, Weblate, or Tolgee).

This issue establishes comprehensive, repository-native validation tooling and CI checks that serve as the safety gate for all subsequent component migration PRs and future community translation contributions.

Architectural Decision Relevant to This Issue

  • Repository-Native Validation: Quality checks run entirely locally and in CI via standard npm scripts (e.g. npm run test:translations / npm run i18n:check).
  • Explicit Dependencies: Direct dependency on parsing utilities (e.g. @formatjs/icu-messageformat-parser or intl-messageformat) declared explicitly in package.json devDependencies, without relying on undeclared transitive imports.
  • Strict 100% Parity Invariant: Every committed message file in the repository—including in-progress selectable: false languages (e.g. Persian feat(i18n): add Persian/Farsi and Iran support #241)—must maintain 100% leaf key parity with en.json. selectable: false controls user-facing selection in the UI, not schema incompleteness in Git.
  • English Canonical Schema: frontend/src/lib/i18n/messages/en.json is the authoritative definition of valid namespaces, keys, ICU variable signatures, and rich-text tags.

What to do

Enhance tests/translations.test.ts (and wire into npm test and npm run test:translations) to enforce:

1. Registry ↔ File Consistency

  • Every language defined in frontend/src/lib/i18n/languages.ts has an existing message JSON file in messages/.
  • Every maintained message file in frontend/src/lib/i18n/messages/ has a corresponding entry in the registry.
  • Valid BCP-47 locale tags and text directions (ltr / rtl).

2. Exact Nested Leaf Key Parity & String Leaf Validation

  • Strict full key parity: Every nested leaf key path in en.json must exist in es.json, pt.json, and fa.json (zero missing keys, zero orphan extra keys).
  • Leaf type validity: Every leaf node must be a non-empty string. Reject null, boolean, numeric, object, or array values at leaf positions.
  • Reject corrupted leaf strings: unescaped raw newlines, trailing JSON syntax leftovers (",, ", }), or unbalanced braces.

3. ICU Syntax Validation

  • Parse every message string across all locales using an explicit parser (@formatjs/icu-messageformat-parser or intl-messageformat).
  • Catch malformed plural rules, invalid case selectors, unclosed brackets, and syntax errors.

4. ICU Variable and Placeholder Parity

  • Compare placeholder arguments between translations and canonical English (e.g. if English specifies {count}, Spanish must not use {total}).
  • For plural and select patterns, verify that the selector argument variable matches English.

5. Rich-Text & Tag Placeholder Parity

  • Where messages include rich-text tags or formatting wrappers (e.g. <bold>...</bold>, <link>...</link>, <ltr>...</ltr>), verify that translations preserve matching opening and closing tag names.

6. TypeScript Key Safety & Unsafe Dynamic Key Checks

  • Verify that tsc --noEmit enforces compile-time type checking of translation keys against AppConfig in messages.d.ts.
  • Check frontend source for unsafe template-literal translation calls (e.g. t(prefix.${var})), enforcing the use of exhaustively typed enum maps.

7. Persian Translation Safeguards

  • Maintain existing checks ensuring fa.json does not silently fall back to English values, respecting the documented intentional identical list (brand names, format tokens, measurements).

What NOT to do

  • Do NOT integrate Crowdin, Weblate, Tolgee, or any external localization SaaS.
  • Do NOT allow partial translations as an acceptable merge state.
  • Do NOT rely on undeclared transitive npm dependencies for message parsing.

Acceptance Criteria

  • npm run test:translations enforces registry consistency, 100% leaf key parity across all committed locales, string leaf validity, ICU syntax validity, parameter placeholder parity, and rich-text tag parity.
  • Negative tests verify that CI fails on:
    • Missing keys in any locale (including selectable: false locales)
    • Orphan extra keys in any locale
    • Non-string or malformed leaf values
    • Malformed ICU syntax
    • Mismatched placeholder argument names vs. English
    • Mismatched rich-text/formatting tags vs. English
    • Invalid literal translation keys in TypeScript
  • All tests pass against the nested message structure.

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. changed the title [-]chore(i18n): add CI checks for translation integrity[/-] [+]chore(i18n): add repository-native translation validation and integrity checks[/+] on Aug 18, 2026
  3. khaira777 commented on Aug 19, 2026

    @khaira777
    ContributorAuthor

    Status: implemented — no-mistakes pipeline running

    What was built

    tests/translations.test.ts is now the repository-native safety gate for all i18n migration PRs and community translation contributions. All eight required checks are live, plus fixture-based negative tests for every failure mode:

    1. Registry ↔ file consistency — every languages.ts language has a messages/<lang>.json file and vice versa; BCP-47 locale tags validated via Intl.Locale (canonical form required); direction must be ltr/rtl.
    2. Exact nested leaf key parity — en.json is canonical: zero missing keys and zero orphan extra keys in es/pt/fa, including selectable: false Persian (feat(i18n): add Persian/Farsi and Iran support #241).
    3. String leaf validity — only non-empty string leaves; rejects null/boolean/number/array leaves, empty objects, raw newlines, trailing JSON artifacts, unbalanced braces.
    4. ICU syntax validation — every message (8,212 across 4 locales) parses with @formatjs/icu-messageformat-parser (new explicit root devDependency ^3.5.17, no undeclared transitive imports).
    5. ICU placeholder & selector parity — argument names and plural/select selector variables must match English in every locale.
    6. Rich-text tag parity — <bold>/<link>-style tags must match English.
    7. TypeScript key safety — all literal t('...') keys defined; no unsafe template-literal t(backtick prefix.${var} backtick) calls (all dynamic keys now carry exhaustive as casts); messages.d.ts AppConfig augmentation verified present.
    8. Persian safeguards — fa.json still must not silently fall back to English (documented intentional-identical list).

    Real bugs the new gate caught

    • es.json addonGroups.addCount dropped the ICU plural form ({count} adicionales vs English plural pattern) → fixed to {count, plural, one {# adicional} other {# adicionales}}.
    • Pre-existing coverage gap: the old collectCalledKeys() extraction regex only matched 2-segment keys, silently skipping 3+ segment keys like whatsapp.send.error.notConnected. Fixed — literal t() call coverage rose from 1,659 → 1,765.
    • Untyped dynamic keys in the WhatsApp page (whatsapp.status.*, whatsapp.kind.*) and Setup page (setup.*Label/Desc/Details) — now exhaustively cast per the dashboard/PrepaidCheckout convention.

    Verification (all green locally)

    • npm run test:translations ✅ (live checks + negative fixtures)
    • npm run lint / npm run lint:backend ✅ (0 errors)
    • npm run build:frontend ✅
    • npm test ✅ (full suite, incl. 65/65 authz-phase3)
    • test:e2e-argentina-flow ✅ 32/32

    Pipeline: 01M0BTK51W0YXPE68HWBVRTQYG — currently in review; PR will be created automatically once all gates pass.

  4. self-assigned this
    on Aug 19, 2026
  5. khaira777 commented on Aug 19, 2026

    @khaira777
    ContributorAuthor

    ✅ Done — merged as 588cc8c via PR #397

    All acceptance criteria met and verified:

    • npm run test:translations enforces registry consistency, 100% leaf key parity vs en.json (all committed locales, incl. selectable:false fa), string leaf validity, ICU syntax validity (@formatjs/icu-messageformat-parser, explicit root devDep ^3.5.17), parameter placeholder parity, and rich-text tag parity.
    • Negative fixture tests verify CI fails on every failure mode: missing keys, orphan keys, non-string/malformed leaves, malformed ICU syntax, mismatched placeholder arguments, mismatched rich-text tags, invalid literal TS keys, and unsafe template-literal t() calls.
    • All tests pass against the nested message structure (8,212 strings across en/es/pt/fa).
    • Wired into npm test (already present) and exposed as npm run i18n:check; documented in AGENTS.md / CONTRIBUTING.md.

    Bugs this gate caught before merge:

    • es.json addonGroups.addCount had dropped the ICU plural form → fixed.
    • Old collectCalledKeys() regex only matched 2-segment keys, silently skipping 3+ segment keys (coverage 1,659 → 1,765) → fixed.
    • 8 untyped dynamic t(\prefix.${var}`)` calls in WhatsApp + Setup pages → now exhaustively cast.

    Verification: test:translations ✅ · lint (frontend + backend) 0 errors ✅ · build:frontend ✅ · full npm test ✅ · e2e-argentina-flow 32/32 ✅ · all 12 CI checks on PR #397 ✅

    Pipeline 01M0BTK51W0YXPE68HWBVRTQYG → outcome: passed. Closing.

  6. khaira777 commented on Aug 19, 2026

    @khaira777
    ContributorAuthor

    Closed as completed.

  7. khaira777 commented on Aug 19, 2026

    @khaira777
    ContributorAuthor

    ⚠️ Problems & observations encountered during this run

    Logging these for the record (post-merge follow-up):

    1. Pipeline launch friction (no-mistakes)

    • The first two attempts to launch no-mistakes axi run in the background (nohup ... > /tmp/nm-382.log 2>&1 &) silently failed — no log file, no process. Root cause: the very long --intent string broke the shell invocation. Workaround that worked: write the intent to a file, INTENT=$(cat ...), then launch. For future runs, keep the intent in a file from the start.
    • Because the foreground CLI was killed by timeout 30 after confirming the run started, the daemon continued but the CLI lost its binding to the run: no-mistakes axi respond initially returned error: no active run to respond to. The first respond --action fix then blocked ~300s waiting for the next gate. Lesson: don't detach the CLI client from an active run — keep a responding terminal attached (or accept the parked gate and poll axi status).

    2. Regression I introduced, caught by the pipeline (auto-fixed)

    • During the tests/translations.test.ts rewrite I dropped the duplicate-key assertion from the original test (dups was computed but never checked). The no-mistakes review gate flagged it (i18n-test-unasserted-duplicate-keys) and auto-fixed it (commit 49f350e6), also adding a negative fixture test. Verified in the merged result — the duplicate-key check is live again.

    3. Pre-existing bugs the new gate exposed (fixed in this PR)

    • es.json addonGroups.addCount had dropped the ICU plural form.
    • Old collectCalledKeys() regex only matched 2-segment keys → 3+ segment keys like whatsapp.send.error.notConnected were silently unchecked (coverage 1,659 → 1,765).

    4. Flaky npm test first run (authz, not related to this change)

    • The first local npm test invocation showed authz-matrix-phase3 failures (expected 403, got 400, staffList is not iterable). A full rerun logged to file passed 65/65 and the whole suite exited 0. Looks like environment/port contention from running it right after the frontend build; did not reproduce. CI on PR chore(i18n): add repository-native translation validation and integrity checks #397 (all 12 checks, incl. linux-tests shards) was green, so this is a local-run flake to keep an eye on, not a regression.

    5. Leftover merged file (from #374's pipeline, not this PR)

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