Skip to content

Conversation

@lyzno1
Copy link
Collaborator

@lyzno1 lyzno1 commented Aug 4, 2025

What & Why

What: Implement English fallback mechanism for missing translation keys in next-intl configuration
Why: Prevents MISSING_MESSAGE errors that crash the application when translation keys are missing from non-English locale files

Technical Implementation

  • deepMerge function: Intelligently merges English fallback messages with current locale
  • Performance optimized: Zero impact for English users, minimal impact for others (single import)
  • Backward compatible: Existing translations remain unchanged, only fills missing keys
  • Comprehensive testing: 9 test cases covering edge cases and real-world scenarios

Pre-PR Checklist

All checks completed:

  • pnpm type-check - Passed
  • pnpm format:check - Passed
  • pnpm lint - Passed
  • pnpm build - Passed
  • pnpm i18n:check - Passed

Type

  • Feature
  • Performance (optimized for minimal impact)

Test Results

PASS i18n/fallback.test.ts - 9/9 tests passed

Before & After

Before: MISSING_MESSAGE errors crash application
After: English fallback displays, application continues normally

This enhancement makes the application more robust and developer-friendly while maintaining full backward compatibility.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. type:feature Request for a brand-new capability. labels Aug 4, 2025
- Add deepMerge function to intelligently merge fallback messages
- English translations automatically fill missing keys in non-English locales
- Zero performance impact for English users (fallback skipped)
- Minimal performance impact for other locales (single additional import)
- Comprehensive test suite with 9 test cases covering edge cases
- Fully backward compatible - existing translations remain unchanged
- Resolves MISSING_MESSAGE errors that previously crashed applications

Technical Details:
- Only loads English fallback for non-English locales
- Uses shallow copy + selective deep merge for memory efficiency
- Preserves existing translations, only fills undefined keys
- Handles nested objects, arrays, null/undefined values correctly
@lyzno1 lyzno1 force-pushed the feat/i18n-fallback-english branch from 000210d to 177593f Compare August 4, 2025 04:54
zhangxuhe1
zhangxuhe1 previously approved these changes Aug 4, 2025
@dosubot dosubot bot added the lgtm Looks good to me; approved by a reviewer. label Aug 4, 2025
Test job was being skipped because it depends on install job,
but install job only ran for source/config changes.
Now install job also runs for test file changes.
@lyzno1 lyzno1 requested a review from zhangxuhe1 August 4, 2025 05:01
Copy link
Contributor

@zhangxuhe1 zhangxuhe1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zhangxuhe1 zhangxuhe1 merged commit 5851e3c into main Aug 4, 2025
15 checks passed
@zhangxuhe1 zhangxuhe1 deleted the feat/i18n-fallback-english branch August 4, 2025 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm Looks good to me; approved by a reviewer. size:L This PR changes 100-499 lines, ignoring generated files. type:feature Request for a brand-new capability.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants