Skip to content

refactor(i18n): derive dayjs locale names instead of hardcoding each one - #45834

Open
rusackas wants to merge 1 commit into
masterfrom
simplify/dayjs-locale-normalization
Open

rusackas wants to merge 1 commit into
masterfrom
simplify/dayjs-locale-normalization

Conversation

@rusackas

Copy link
Copy Markdown
Member

SUMMARY

Follow-up to #45605. DAYJS_LOCALE_MAPPING hardcoded three Flask-Babel→dayjs locale name conversions, but two of them (zh_TW → zh-tw, pt_BR → pt-br) are pure case/separator reformatting — 'zh_TW'.toLowerCase().replace(/_/g, '-') already produces the exact registered dayjs locale name. Only zh → zh-cn is a genuine rename: dayjs ships its own bare zh locale, but this project imports zh-cn specifically, so Babel's generic zh code needs an explicit redirect.

Replaced the three-entry map with a toDayjsLocale() helper: a one-entry override map for the genuine rename, falling back to the generic normalization for everything else. Same behavior today, but any future locale whose Babel code and dayjs name differ only by case/separator now works automatically, without a new map entry, as long as the matching dayjs locale file is imported.

Also filed iamkun/dayjs#3345 upstream — dayjs's own locale resolver already lowercases input and has a hyphen-split fallback for unmatched names, it just never treats _ as a separator, so any app feeding it gettext/ICU-style locale codes directly hits the same silent-fallback trap Superset did here.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — internal refactor, no behavior change.

TESTING INSTRUCTIONS

cd superset-frontend
npx jest src/hooks/useLocale.test.tsx src/preamble.test.ts

26/26 passing. Same manual check as #45605 still applies: set DEFAULT_LOCALE = 'zh_TW' and confirm Ant Design components and dayjs date formatting still render in Traditional Chinese.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

🤖 Generated with Claude Code

Two of the three DAYJS_LOCALE_MAPPING entries added in #45605 (zh_TW ->
zh-tw, pt_BR -> pt-br) are pure case/separator differences between
Flask-Babel's locale codes and dayjs's locale names. Replace the static
map with a generic normalizer plus a single explicit override for the
one entry that's a genuine rename (zh -> zh-cn, since this project
imports the zh-cn dayjs locale rather than dayjs's own bare zh locale).

Any future locale whose Babel code and dayjs name differ only by case
or separator now works without a new map entry, as long as the
matching dayjs locale file is imported.

Co-Authored-By: Evan Rusackas <evan@preset.io>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@codeant-ai-for-open-source

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: 6fc5a596cf2b

@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.63%. Comparing base (2350348) to head (6fc5a59).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #45834   +/-   ##
=======================================
  Coverage   84.63%   84.63%           
=======================================
  Files        3069     3069           
  Lines      205446   205448    +2     
  Branches    48306    48305    -1     
=======================================
+ Hits       173879   173881    +2     
  Misses      28277    28277           
  Partials     3290     3290           
Flag Coverage Δ
javascript 80.81% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sadpandajoe
sadpandajoe self-requested a review October 29, 2026 18:30

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant