Skip to content

[CMSDS-4042] Complete DatePicker localization#4067

Open
jack-ryan-nava-pbc wants to merge 14 commits into
mainfrom
jryan/cmsds-4042-date-picker-localization
Open

[CMSDS-4042] Complete DatePicker localization#4067
jack-ryan-nava-pbc wants to merge 14 commits into
mainfrom
jryan/cmsds-4042-date-picker-localization

Conversation

@jack-ryan-nava-pbc
Copy link
Copy Markdown
Collaborator

Summary

How to test

  1. Run locally and open SingleInputDateField story in Storybook
  2. Select the "With Picker" story
  3. Change the localization to Spanish
Screenshot 2026-05-22 at 4 35 13 PM
  1. Months are translated
  2. Days are translated
  3. Mask is localized

Checklist

  • Prefixed the PR title with the Jira ticket number as [CMSDS-####] Title or [NO-TICKET] if this is unticketed work.
  • Selected appropriate Type (only one) label for this PR, if it is a breaking change, label should only be Type: Breaking
  • Selected appropriate Impacts, multiple can be selected.
  • Selected appropriate release milestone

@jack-ryan-nava-pbc jack-ryan-nava-pbc self-assigned this May 22, 2026
@jack-ryan-nava-pbc jack-ryan-nava-pbc added Type: Fixed Indicates an unexpected problem or unintended behavior Impacts: Core Impacts the core DS primarily, changes may occur in other themes as well. labels May 22, 2026
| 'toYear'
>;

const getLocale = () => {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Going with a switch here in case we decide to localize additional languages. We just add a new case for any additional language


type MaskType = 'DATE_MASK' | 'PHONE_MASK' | 'ZIP_MASK' | 'SSN_MASK' | 'CURRENCY_MASK';
type TaggedFunction = MaskFunction & { __maskType: MaskType };
const createTaggedFunction = (fn: MaskFunction, fnType: MaskType) => {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ok, so stick with me here. The idea of the tagged function is to make it easier to check if we're using the correct function in the if checks below. I've only added it for the createDateMask function to reduce the scope of the changes in this PR. The idea is that instead of checking for literal object equality like maskFn === DATE_MASK we append a "tag" to the function in question so we can explicitly control and check that type.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ideally everyone of the *_MASK functions in this file would be converted to a Tagged function, but since those functions are used in TextField as well, I don't want to expand the scope and risk breaking things over there.


return formattedDate;
}),
'DATE_MASK'
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

^ This string is the tag we check for later.


return formattedDate;
});
export const DATE_MASK: TaggedFunction = createDateMask();
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I could in theory remove the export statement here, I'm pretty sure this is only being used in the SingleInputDateField component, but I want to minimize potential downstream changes. Let me know if you disagree.


// Date mask needs to return the default empty mask when not focused
if (maskFn === DATE_MASK && !focused) {
if ('__maskType' in maskFn && maskFn.__maskType === 'DATE_MASK' && !focused) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

If I converted every function in this file to a TaggedFunction I could remove the '__maskType' in maskFn but I think that is an increase in scope that I don't want to do just yet.

Copy link
Copy Markdown
Collaborator

@derek-cmsds derek-cmsds left a comment

Choose a reason for hiding this comment

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

Selecting a day greater than 12 while in the Spanish locale appears to break the picker.

  1. Load the SingleInputDateField With Picker Story.
  2. Switch to the Spanish locale.
  3. Select a day of the month greater than 12.
  4. Click the picker again.
  5. Verify that a small, blank, white box appears instead of the picker.

@jack-ryan-nava-pbc
Copy link
Copy Markdown
Collaborator Author

Selecting a day greater than 12 while in the Spanish locale appears to break the picker.

  1. Load the SingleInputDateField With Picker Story.
  2. Switch to the Spanish locale.
  3. Select a day of the month greater than 12.
  4. Click the picker again.
  5. Verify that a small, blank, white box appears instead of the picker.

@derek-cmsds this should be resolved in the latest commit.

Comment thread packages/design-system/src/components/i18n.ts
Copy link
Copy Markdown
Collaborator

@tamara-corbalt tamara-corbalt left a comment

Choose a reason for hiding this comment

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

Looks like it's working great in Storybook! Seeing some local unit test failures though — related to where we import es from date-fns/locale

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

Labels

Impacts: Core Impacts the core DS primarily, changes may occur in other themes as well. Type: Fixed Indicates an unexpected problem or unintended behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug:] Calendar picker incompletely localized

3 participants