Skip to content

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

Merged
khaira777 merged 3 commits into
mainfrom
chore/382-i18n-validation
Aug 19, 2026
Merged

khaira777 merged 3 commits into
mainfrom
chore/382-i18n-validation

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

Intent

chore(i18n): add repository-native translation validation and integrity checks (issue #382, epic #372 Phase 1 final step). Commit 09508ec on branch chore/382-i18n-validation rewrites tests/translations.test.ts into a comprehensive safety gate: (1) registry-file consistency via languages.ts (BCP-47 tags, ltr/rtl direction); (2) exact nested leaf key parity with en.json as canonical (zero missing, zero orphan, incl. selectable:false fa); (3) string leaf validity (no non-string/empty/array/empty-object leaves, no corrupted strings); (4) ICU syntax validation of all messages via @formatjs/icu-messageformat-parser (new root devDependency ^3.5.17); (5) ICU placeholder argument + plural/select selector parity vs en.json; (6) rich-text tag parity vs en.json; (7) TypeScript key safety: literal t() keys defined, no unsafe template-literal t() calls (all dynamic keys now carry exhaustive as-casts in whatsapp/setup pages), messages.d.ts AppConfig augmentation present; (8) fa.json no-silent-English-fallback safeguards. Also fixes a real es.json plural mismatch (addonGroups.addCount) and adds npm run i18n:check alias. Negative fixture tests verify every failure mode is detected. Exclusions: do not modify translation wording/keys beyond the es.json addCount fix, do not touch backend runtime code, do not add new dependencies beyond @formatjs/icu-messageformat-parser, do not run or modify e2e playwright tests, do not modify CI workflows, keep commits free of AI attribution footers.

What Changed

  • Implemented comprehensive repository-native translation validation in tests/translations.test.ts using @formatjs/icu-messageformat-parser to enforce registry consistency, leaf key parity against canonical en.json, string leaf validity, ICU syntax and placeholder parity, rich-text tag parity, TypeScript key safety, and Persian fallback safeguards, backed by negative fixture tests.
  • Added the i18n:check npm script alias, installed @formatjs/icu-messageformat-parser dev dependency, and updated AGENTS.md and CONTRIBUTING.md with translation verification guidelines.
  • Added exhaustive type assertions on dynamic t() calls in the WhatsApp and Setup pages and updated es.json to use correct ICU plural formatting for addonGroups.addCount.

Risk Assessment

✅ Low: The translation validation test suite and ICU message integrity checks are well-bounded, robustly tested with negative fixtures, and introduce no runtime risks.

Testing

Exercised the full i18n safety gate test suite (npm run i18n:check / npm run test:translations), verified ICU plural formatting for addonGroups.addCount across singular and plural counts, validated dynamic key resolution on WhatsApp and Setup screens, and confirmed all 16 negative fixture detection cases; visual UI screenshots were not applicable as this change is a repository-native translation validation and test integrity gate with type-level key assertions.

Evidence: i18n-check-output.log

> [email protected] i18n:check > npm run test:translations > [email protected] test:translations > ts-node --transpile-only -P tests/tsconfig.json tests/translations.test.ts Translation integrity: en <-> es <-> pt <-> fa ✓ registry ↔ files consistent (4 languages, 4 files) en.json: 2053 leaf keys es.json: 2053 leaf keys pt.json: 2053 leaf keys fa.json: 2053 leaf keys ✓ no duplicate keys within translation files ✓ exact leaf key parity with en.json (no missing, no orphan keys) ✓ all leaves are non-empty strings (no empty objects/arrays/null/booleans/numbers) ✓ no malformed values ✓ all messages parse as valid ICU (plurals, selects, brackets) ✓ placeholder arguments and plural/select selectors match en.json in all locales ✓ rich-text tags match en.json in all locales ✓ no undefined keys (1765 literal t() calls covered) ✓ no unsafe template-literal t() calls (all dynamic keys exhaustively cast) ✓ messages.d.ts AppConfig augmentation present (compile-time key checks active) ✓ no untranslated fa.json values (31 intentional shared values) ✅ All translation integrity checks passed. Negative tests (fixture-based): ✓ all negative fixtures detected by their validators ✅ All translation integrity checks + negative tests passed.


> [email protected] i18n:check
> npm run test:translations


> [email protected] test:translations
> ts-node --transpile-only -P tests/tsconfig.json tests/translations.test.ts

Translation integrity: en <-> es <-> pt <-> fa
  ✓ registry ↔ files consistent (4 languages, 4 files)
  en.json: 2053 leaf keys
  es.json: 2053 leaf keys
  pt.json: 2053 leaf keys
  fa.json: 2053 leaf keys
  ✓ no duplicate keys within translation files
  ✓ exact leaf key parity with en.json (no missing, no orphan keys)
  ✓ all leaves are non-empty strings (no empty objects/arrays/null/booleans/numbers)
  ✓ no malformed values
  ✓ all messages parse as valid ICU (plurals, selects, brackets)
  ✓ placeholder arguments and plural/select selectors match en.json in all locales
  ✓ rich-text tags match en.json in all locales
  ✓ no undefined keys (1765 literal t() calls covered)
  ✓ no unsafe template-literal t() calls (all dynamic keys exhaustively cast)
  ✓ messages.d.ts AppConfig augmentation present (compile-time key checks active)
  ✓ no untranslated fa.json values (31 intentional shared values)

✅ All translation integrity checks passed.

Negative tests (fixture-based):
  ✓ all negative fixtures detected by their validators

✅ All translation integrity checks + negative tests passed.
Evidence: i18n-verification-summary.txt

=== FLO-CAFE i18n TRANSLATION VALIDATION & REPOSITORY INTEGRITY VERIFICATION REPORT === 1. PRODUCT BEHAVIOR: ICU Plural Formatting (addonGroups.addCount fix) -------------------------------------------------------------------------------- Raw ICU Templates: EN: {count, plural, one {# addon} other {# addons}} ES: {count, plural, one {# adicional} other {# adicionales}} PT: {count, plural, one {# adicional} other {# adicionais}} FA: {count, plural, one {# افزونه} other {# افزونه}} Formatted Output (End-User View): count = 1: EN: 1 addon ES: 1 adicional PT: 1 adicional FA: ۱ افزونه count = 5: EN: 5 addons ES: 5 adicionales PT: 5 adicionais FA: ۵ افزونه 2. TYPE-SAFE DYNAMIC TRANSLATION KEY RESOLUTION (WhatsApp & Setup pages) -------------------------------------------------------------------------------- WhatsApp Statuses: whatsapp.status.failed -> EN: "Failed" | ES: "Falló" | PT: "Falhou" | FA: "ناموفق" whatsapp.status.queued -> EN: "Queued" | ES: "En cola" | PT: "Na fila" | FA: "در صف" whatsapp.status.typing -> EN: "Typing" | ES: "Escribiendo" | PT: "Digitando" | FA: "در حال تایپ" whatsapp.status.sent -> EN: "Sent" | ES: "Enviado" | PT: "Enviada" | FA: "ارسال‌شده" whatsapp.status.delivered -> EN: "Delivered" | ES: "Entregado" | PT: "Entregue" | FA: "تحویل‌شده" whatsapp.status.read -> EN: "Read" | ES: "Leído" | PT: "Lida" | FA: "خوانده‌شده" WhatsApp Message Kinds: whatsapp.kind.bill_receipt -> EN: "Bill receipt" | ES: "Recibo" | PT: "Comprovante de conta" | FA: "رسید صورت‌حساب" whatsapp.kind.manual_reply -> EN: "Manual reply" | ES: "Respuesta manual" | PT: "Resposta manual" | FA: "پاسخ دستی" whatsapp.kind.auto_followup -> EN: "Auto follow-up" | ES: "Seguimiento automático" | PT: "Acompanhamento automático" | FA: "پیگیری خودکار" Setup Options: setup.emptyLabel -> EN: "Empty" | ES: "Vacío" | PT: "Vazio" | FA: "خالی" setup.expressLabel -> EN: "Express" | ES: "Express" | PT: "Expresso" | FA: "سریع" setup.demoLabel -> EN: "Demo" | ES: "Demo" | PT: "Demonstração" | FA: "نمایشی" 3. SAFETY GATE SUITE SUMMARY -------------------------------------------------------------------------------- Command: npm run i18n:check (alias for npm run test:translations) Checked Locales: en, es, pt, fa (2,053 leaf keys each, total 8,212 strings) Literal t() Calls Verified: 1,765 frontend call sites Result: 100% PASS across all 8 validation gates and fixture negative tests. ===

================================================================================
FLO-CAFE i18n TRANSLATION VALIDATION & REPOSITORY INTEGRITY VERIFICATION REPORT
================================================================================

1. PRODUCT BEHAVIOR: ICU Plural Formatting (addonGroups.addCount fix)
--------------------------------------------------------------------------------
Raw ICU Templates:
  EN: {count, plural, one {# addon} other {# addons}}
  ES: {count, plural, one {# adicional} other {# adicionales}}
  PT: {count, plural, one {# adicional} other {# adicionais}}
  FA: {count, plural, one {# افزونه} other {# افزونه}}

Formatted Output (End-User View):
  count = 1:
    EN: 1 addon
    ES: 1 adicional
    PT: 1 adicional
    FA: ۱ افزونه
  count = 5:
    EN: 5 addons
    ES: 5 adicionales
    PT: 5 adicionais
    FA: ۵ افزونه


2. TYPE-SAFE DYNAMIC TRANSLATION KEY RESOLUTION (WhatsApp & Setup pages)
--------------------------------------------------------------------------------
WhatsApp Statuses:
  whatsapp.status.failed -> EN: "Failed" | ES: "Falló" | PT: "Falhou" | FA: "ناموفق"
  whatsapp.status.queued -> EN: "Queued" | ES: "En cola" | PT: "Na fila" | FA: "در صف"
  whatsapp.status.typing -> EN: "Typing" | ES: "Escribiendo" | PT: "Digitando" | FA: "در حال تایپ"
  whatsapp.status.sent -> EN: "Sent" | ES: "Enviado" | PT: "Enviada" | FA: "ارسال‌شده"
  whatsapp.status.delivered -> EN: "Delivered" | ES: "Entregado" | PT: "Entregue" | FA: "تحویل‌شده"
  whatsapp.status.read -> EN: "Read" | ES: "Leído" | PT: "Lida" | FA: "خوانده‌شده"

WhatsApp Message Kinds:
  whatsapp.kind.bill_receipt -> EN: "Bill receipt" | ES: "Recibo" | PT: "Comprovante de conta" | FA: "رسید صورت‌حساب"
  whatsapp.kind.manual_reply -> EN: "Manual reply" | ES: "Respuesta manual" | PT: "Resposta manual" | FA: "پاسخ دستی"
  whatsapp.kind.auto_followup -> EN: "Auto follow-up" | ES: "Seguimiento automático" | PT: "Acompanhamento automático" | FA: "پیگیری خودکار"

Setup Options:
  setup.emptyLabel -> EN: "Empty" | ES: "Vacío" | PT: "Vazio" | FA: "خالی"
  setup.expressLabel -> EN: "Express" | ES: "Express" | PT: "Expresso" | FA: "سریع"
  setup.demoLabel -> EN: "Demo" | ES: "Demo" | PT: "Demonstração" | FA: "نمایشی"


3. SAFETY GATE SUITE SUMMARY
--------------------------------------------------------------------------------
Command: npm run i18n:check (alias for npm run test:translations)
Checked Locales: en, es, pt, fa (2,053 leaf keys each, total 8,212 strings)
Literal t() Calls Verified: 1,765 frontend call sites
Result: 100% PASS across all 8 validation gates and fixture negative tests.
================================================================================
Evidence: i18n-validation-evidence.log
=== FloCafe i18n Translation Validation & Integrity Test Suite Evidence ===

--- npm run i18n:check stdout ---

> [email protected] i18n:check
> npm run test:translations


> [email protected] test:translations
> ts-node --transpile-only -P tests/tsconfig.json tests/translations.test.ts

Translation integrity: en <-> es <-> pt <-> fa
  ✓ registry ↔ files consistent (4 languages, 4 files)
  en.json: 2053 leaf keys
  es.json: 2053 leaf keys
  pt.json: 2053 leaf keys
  fa.json: 2053 leaf keys
  ✓ no duplicate keys within translation files
  ✓ exact leaf key parity with en.json (no missing, no orphan keys)
  ✓ all leaves are non-empty strings (no empty objects/arrays/null/booleans/numbers)
  ✓ no malformed values
  ✓ all messages parse as valid ICU (plurals, selects, brackets)
  ✓ placeholder arguments and plural/select selectors match en.json in all locales
  ✓ rich-text tags match en.json in all locales
  ✓ no undefined keys (1765 literal t() calls covered)
  ✓ no unsafe template-literal t() calls (all dynamic keys exhaustively cast)
  ✓ messages.d.ts AppConfig augmentation present (compile-time key checks active)
  ✓ no untranslated fa.json values (31 intentional shared values)

✅ All translation integrity checks passed.

Negative tests (fixture-based):
  ✓ all negative fixtures detected by their validators

✅ All translation integrity checks + negative tests passed.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ tests/translations.test.ts:535 - findDuplicateKeys is invoked during translation file loading and populates dups, but dups is never checked or asserted in run(). As a result, duplicate keys within a translation JSON object are not rejected during test execution.

🔧 Fix: assert duplicate keys in translation validation test
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • npm run test:translations
  • npm run i18n:check
  • npm run test:rtl-foundation
  • npm run test:rtl-setup-auth-settings
  • npm run test:rtl-dashboard-pos-common
  • npm run test:rtl-kds-server-whatsapp
  • IntlMessageFormat formatting for addonGroups.addCount across en, es, pt, fa
  • Dynamic key resolution verification for WhatsApp and Setup pages across en, es, pt, fa
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…ty checks

Expand tests/translations.test.ts into the safety gate for all i18n
migration PRs and community contributions. Adds registry-to-file
consistency, en-canonical leaf key parity, string leaf validity, ICU
syntax validation via @formatjs/icu-messageformat-parser, placeholder
and rich-text tag parity vs English, TypeScript key safety (exhaustively
typed dynamic keys + AppConfig augmentation), and fixture-based negative
tests for every failure mode. Fixes a real es.json plural mismatch and
types previously untyped dynamic t() template literals in the WhatsApp
and Setup pages. Adds an i18n:check alias for discoverability.
@khaira777
khaira777 merged commit 588cc8c into main Aug 19, 2026
12 checks passed
@khaira777
khaira777 deleted the chore/382-i18n-validation branch August 19, 2026 01:50
@khaira777 khaira777 self-assigned this Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant