fix: normalize "original" locale to "en" for datetime formatting - #4472
fix: normalize "original" locale to "en" for datetime formatting#4472leonardthethird wants to merge 6 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughDate formatting utilities now normalize the ChangesLocale-normalized formatting
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ 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:
|
|
@claude deal with failing unit tests / frontend checks. |
|
Claude finished @leonardthethird's task in 1m 35s —— View job Fixed failing frontend lint check
Root cause: The |
|
@claude can you resolve merge conflicts with |
|
Claude finished @ncarazon's task in 10m 5s —— View job Merge conflict analysisI can't perform the actual merge in this environment (both Conflict inventoryOnly three files really matter — the rest of main's ~964 changed files are additions/edits our branch never touched, so git will auto-take main's version there. 1. Main removed the legacy JSON config and switched to flat config ( 2. Main deleted the whole file (the homepage was restructured — a batch of 3. Main changed The other four PR files ( The
|
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>
…ization Adds `formatIntlDate` / `formatIntlDistance` in @/utils/formatters/date so `normalizeIntlLocale` is applied inside the wrapper, and callers stop needing to normalize the "original" locale at every site. Also normalizes the `lang` prop inside RelativeTime, since the underlying <relative-time> web component uses it for Intl formatting and would otherwise hit the same OS-language-fallback bug. An ESLint `no-restricted-imports` rule now blocks direct imports of `intlFormat` / `intlFormatDistance` from date-fns so a future contributor gets a lint error instead of a subtle locale bug in Untranslated mode. Co-authored-by: Nikita <93587872+ncarazon@users.noreply.github.com>
Restore the pre-existing workaround (and its comment) that defaults the locale to "en" when it is "original", to avoid the server/client hydration mismatch on `localValue`. The centralized `normalizeIntlLocale` covers Intl call sites, but this component-level guard is what keeps SSR and CSR producing the same string here. Co-authored-by: Nikita <93587872+ncarazon@users.noreply.github.com>
5c1b9c2 to
14b5210
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@front_end/eslint.config.mjs`:
- Around line 73-76: Update the custom ESLint error message in the import
restriction containing importNames ["intlFormat", "intlFormatDistance"] to
recommend the actual exported helpers formatDate and formatRelativeDate instead
of formatIntlDate and formatIntlDistance. Preserve the existing guidance about
normalizing the “original” locale.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6efcfa78-36e0-4aa7-af70-15e7eead629c
📒 Files selected for processing (1)
front_end/eslint.config.mjs
|
@claude Run Unit Tests pipeline has failed. Looks like there are formatting errors. Could you please address it? |
|
Claude finished @ncarazon's task in 2m 2s —— View job Fixed prettier formatting error in
|
Co-authored-by: Nikita <93587872+ncarazon@users.noreply.github.com>
Hug the last object argument in the intlFormat call to satisfy prettier's print-width rule. Co-authored-by: Nikita <93587872+ncarazon@users.noreply.github.com>
|
@claude please merge. |
|
Claude finished @SylvainChevalier's task in 23s —— View job Unable to merge this PRI'm not able to merge pull requests — my GitHub App permissions don't include branch operations (merging, rebasing, force-pushing). This is a deliberate safety restriction; see the FAQ for details. The PR is approved by @ncarazon and CI is passing, so you (or any maintainer) should be able to hit the Merge pull request button directly, or from the CLI: gh pr merge 4472 --squash # or --merge / --rebase, whichever matches this repo's conventionIf you'd like me to do something else on this branch first (rebase onto latest |
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
Bug Fixes
Refactor
Chores / Style