fix: normalize "original" locale to "en" for datetime formatting#4472
fix: normalize "original" locale to "en" for datetime formatting#4472leonardthethird wants to merge 1 commit intomainfrom
Conversation
When users select "Untranslated" mode, the locale is set to "original". This is not a valid BCP 47 locale tag, so browser Intl APIs fall back to the OS language, causing mixed-language strings like "Revealed el próximo mes". Add a normalizeIntlLocale() utility that maps "original" to "en" and apply it consistently across all components that pass locale to intlFormat, intlFormatDistance, or the <relative-time> element. Fixes #4122 Co-authored-by: leonardthethird <leonardthethird@users.noreply.github.com>
📝 WalkthroughWalkthroughThis PR introduces locale normalization across multiple frontend components and utilities to ensure consistent internationalization (Intl) API usage. A new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
front_end/src/utils/formatters/date.ts (1)
192-198: Add a small regression test aroundnormalizeIntlLocale.This helper is now the single guard for Untranslated mode, so a focused test for
"original" -> "en"plus one passthrough locale would make the bugfix harder to regress.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@front_end/src/utils/formatters/date.ts` around lines 192 - 198, Add a small unit test suite for normalizeIntlLocale: import normalizeIntlLocale from its module, then add two tests — one asserting normalizeIntlLocale("original") returns "en" and another asserting normalizeIntlLocale("fr") (or "en-US") returns the same input (passthrough). Use the project's test framework (e.g., Jest) and place the test alongside other utils tests so it runs in CI; name the tests clearly like "returns en for 'original' (Untranslated mode)" and "passes through valid locales".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@front_end/src/utils/formatters/date.ts`:
- Around line 192-198: Add a small unit test suite for normalizeIntlLocale:
import normalizeIntlLocale from its module, then add two tests — one asserting
normalizeIntlLocale("original") returns "en" and another asserting
normalizeIntlLocale("fr") (or "en-US") returns the same input (passthrough). Use
the project's test framework (e.g., Jest) and place the test alongside other
utils tests so it runs in CI; name the tests clearly like "returns en for
'original' (Untranslated mode)" and "passes through valid locales".
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7c986d69-6129-4fac-b08b-7fe3c66e37ad
📒 Files selected for processing (5)
front_end/src/app/(main)/(home)/components/research_and_updates.tsxfront_end/src/components/consumer_post_card/upcoming_cp.tsxfront_end/src/components/cp_reveal_time/cp_reveal_time.tsxfront_end/src/components/ui/local_daytime.tsxfront_end/src/utils/formatters/date.ts
🚀 Preview EnvironmentYour preview environment is ready!
Details
ℹ️ Preview Environment InfoIsolation:
Limitations:
Cleanup:
|
Fix datetime strings being partially localized based on OS language when site is in "Untranslated" mode.
When users select "Untranslated" mode, the locale is set to "original" which is not a valid BCP 47 tag. Browser Intl APIs fall back to OS language, causing mixed-language strings like "Revealed el próximo mes".
Adds a
normalizeIntlLocale()utility that maps "original" to "en" and applies it consistently across all components using Intl-based date formatting.Fixes #4122
Generated with Claude Code
Summary by CodeRabbit