Skip to content

fix(Calendar): localize weekday header names to the provider locale - #5117

Closed
HelloOjasMutreja wants to merge 2 commits into
meta:mainfrom
HelloOjasMutreja:fix/calendar-locale-weekday-names
Closed

HelloOjasMutreja wants to merge 2 commits into
meta:mainfrom
HelloOjasMutreja:fix/calendar-locale-weekday-names

Conversation

@HelloOjasMutreja

Copy link
Copy Markdown
Contributor

Summary

Part of #5074, which covers several locale-ignoring paths across Calendar, DateInput/DateTimeInput, Timestamp, and PowerSearch. This PR scopes to just Calendar's weekday header names; the remaining paths need their own investigation and will follow as separate PRs.

Evidence

useCalendarDays.ts hardcoded the weekday abbreviations:

const names = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];

regardless of the ambient InternationalizationProvider locale. A tree wrapped in locale="es-ES" (or any non-English locale) still rendered English weekday headers.

Fix

Read InternationalizationContext.locale inside 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 to Intl.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 via Intl.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. Full Calendar.test.tsx suite (116 tests) passes.

Test plan

  • vitest run on Calendar.test.tsx + dayCellUtils.test.ts: 116/116 passing
  • Verified new test fails without the fix, passes with it
  • eslint clean on touched files
  • tsc --noEmit: no new errors on touched files
  • Changeset added

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.
@vercel

vercel Bot commented Aug 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 16, 2026 4:47pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 16, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Aug 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

Calendar (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1332 -
Complexity N/A Very High (135) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

: (() => {
const formatter = new Intl.DateTimeFormat(locale, {
weekday: 'short',
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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']

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

@nynexman4464

Copy link
Copy Markdown
Contributor

Thank you for taking this on and for adding the provider-locale regression coverage. While reviewing the weekday width, we found that the existing Su / Mo / Tu labels correspond to CLDR's stand-alone.short data, a width that Intl.DateTimeFormat does not expose. Browser weekday: 'short' can also produce full weekday names in some locales.

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.

@HelloOjasMutreja

Copy link
Copy Markdown
Contributor Author

Closing as superseded: #5190 landed on main with a more thorough CLDR-based approach to the same problem (real stand-alone.short CLDR data with a generated runtime table, rather than the Intl.DateTimeFormat approach here), touching the same useCalendarDays.ts/Calendar.test.tsx files. Thanks to nynexman4464 for the more complete fix.

This branch was successfully deployed

1 active deployment
Preview — 711aa24d Deployed Aug 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants