Repository navigation
fix(Calendar): localize weekday header names to the provider locale - #5117
HelloOjasMutreja wants to merge 2 commits into
Conversation
useCalendarDays hardcoded the weekday abbreviations ('Su', 'Mo', 'Tu',
...) regardless of the ambient InternationalizationProvider locale, so
a tree wrapped in locale="es-ES" (or any non-English locale) still
rendered English weekday headers.
English keeps its existing two-letter abbreviations as a deliberate
compact convention (existing tests assert the exact 'Su'/'Mo' strings)
-- switching everything to Intl's 'short' format would give three
letters (Sun, Mon...) and regress the overwhelmingly common default
case for no reason. Every other locale now uses its own short weekday
form via Intl.DateTimeFormat, the only correct-by-construction source
for non-English abbreviations.
Part of meta#5074, which covers several locale-ignoring paths across
Calendar, DateInput/DateTimeInput, Timestamp, and PowerSearch. Scoping
this PR to Calendar's weekday headers; the rest need their own
investigation and will follow as separate PRs.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsCalendar (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
| : (() => { | ||
| const formatter = new Intl.DateTimeFormat(locale, { | ||
| weekday: 'short', | ||
| }); |
There was a problem hiding this comment.
Nice to see this moving off the hardcoded English array. One correctness issue: the anchor dates are UTC midnight, but the formatter has no timeZone, so it converts them to the viewer's zone before finding the weekday. Under TZ=America/Los_Angeles, the Sunday anchor formats as Saturday and the entire header shifts one day; CI misses this because its runner is UTC. Could you add timeZone: 'UTC' and add a regression test that runs under a negative UTC offset?
| const baseLanguage = new Intl.Locale(locale).language; | ||
| const names = | ||
| baseLanguage === 'en' | ||
| ? ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'] |
There was a problem hiding this comment.
I agree that we should preserve a compact header, but I don't think an English-only branch is the right long-term model.
Su / Mo / Tu / … is CLDR's stand-alone.short width. Unfortunately, Intl.DateTimeFormat does not expose that width: weekday: 'short' gives CLDR's abbreviated form (Sun / Mon / …), while weekday: 'narrow' gives S / M / T / ….
short also does not guarantee a compact result across locales. In current CLDR, Arabic's short values are the full weekday names, and Hebrew or European Portuguese can still be roughly twice the width of English.
I'm looking into whether there is a lightweight way to consume CLDR's stand-alone short data. For now, I'm leaning toward narrow as our best option: it is consistently compact and fully browser-supported, even though some labels are ambiguous without their column position. Could we use that consistently rather than special-casing English?
|
Thank you for taking this on and for adding the provider-locale regression coverage. While reviewing the weekday width, we found that the existing We followed that research through in #5190: it generates the compact CLDR data for the locales shipped by core, preserves the existing English labels, avoids the date-anchor timezone issue, and keeps the data synchronized when Crowdin adds a locale. That PR is now ready for review, so we plan to proceed with it rather than ask you to keep revising this implementation. I wanted to share the outcome here and acknowledge that your PR surfaced and proved the underlying bug. |
|
Closing as superseded: #5190 landed on main with a more thorough CLDR-based approach to the same problem (real |
Summary
Part of #5074, which covers several locale-ignoring paths across
Calendar,DateInput/DateTimeInput,Timestamp, andPowerSearch. This PR scopes to justCalendar's weekday header names; the remaining paths need their own investigation and will follow as separate PRs.Evidence
useCalendarDays.tshardcoded the weekday abbreviations:regardless of the ambient
InternationalizationProviderlocale. A tree wrapped inlocale="es-ES"(or any non-English locale) still rendered English weekday headers.Fix
Read
InternationalizationContext.localeinside the hook. English keeps its existing two-letter abbreviations as a deliberate compact convention (confirmed by existing tests asserting the exact'Su'/'Mo'strings). Switching everything toIntl.DateTimeFormat's'short'format would give three letters (Sun,Mon, ...) and regress the overwhelmingly common default case for no reason. Every other locale now uses its own short weekday form viaIntl.DateTimeFormat, the only correct-by-construction source for non-English abbreviations.Test notes
Added a regression test asserting Spanish locale (
es-ES) produces the correct localized weekday headers (dom,lun,mar,mié,jue,vie,sáb). Verified the test fails without the fix (falls back to the hardcoded English strings) and passes with it restored. FullCalendar.test.tsxsuite (116 tests) passes.Test plan
vitest runonCalendar.test.tsx+dayCellUtils.test.ts: 116/116 passingeslintclean on touched filestsc --noEmit: no new errors on touched files