I18n
Tests for validating translation files and i18n functionality.
Internationalization (i18n) Tests
Tests for validating translation files and i18n functionality.
Translation Consistency Tests
File: translation-consistency.test.ts
Validates that all locale files (src/locales/*.json) have consistent keys with the English source file (en.json). This prevents runtime errors when users switch languages.
What it checks
- All non-English locale files have the same keys as
en.json - No extra keys exist in non-English locales
- No missing keys in non-English locales
- All locale files are valid JSON
Why this matters
If es.json is missing a key that exists in en.json, users who switch to Spanish will see:
- Untranslated keys appearing in the UI
- Runtime errors from next-intl
- Broken user experience
This test catches these issues before they reach production.
Usage
# Run i18n tests
bun run test src/__tests__/i18n/
# Run specific test
bun run test src/__tests__/i18n/translation-consistency.test.ts
Adding new locale files
When adding a new locale:
- Copy
src/locales/en.jsontosrc/locales/{locale-code}.json - Translate all values (keep keys identical)
- Run tests to verify consistency:
bun run test src/__tests__/i18n/ - Add the locale to
src/components/i18n/language-selector.tsx