Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide locale setting on nimble-theme-provider #1293

Closed
Tracked by #1011
mollykreis opened this issue Jun 12, 2023 · 0 comments · Fixed by #1410
Closed
Tracked by #1011

Provide locale setting on nimble-theme-provider #1293

mollykreis opened this issue Jun 12, 2023 · 0 comments · Fixed by #1410
Assignees
Labels
enhancement New feature or request needs investigation Further research is needed to identify solution

Comments

@mollykreis
Copy link
Contributor

😯 Problem to Solve

The nimble-theme-provider element should have a way to specify a locale that can be used by various components for sorting and formatting. We should also consider having the default value of locale be determined by the browser.

Some places where this could be used:

  • locale-aware string sorting on columns in the nimble-table
  • number formatting in the nimble-number-field
  • number/date formatting on columns in the nimble-table
  • date formatting in a future nimble-date-picker

This has been discussed in a few different places:

💁 Proposed Solution

Add a new property/attribute to the nimble-theme-provider that allows components to access the current locale of an application. This attribute can have a default value based on the application, but it should be configurable by an application using nimble.

More investigation is still needed to solidify a recommendation on string sorting, such as for string column sorting in the table. We should consider how the Collator compares to the current implementation of localeCompare.

@mollykreis mollykreis added enhancement New feature or request triage New issue that needs to be reviewed labels Jun 12, 2023
@m-akinc m-akinc added needs investigation Further research is needed to identify solution and removed triage New issue that needs to be reviewed labels Jun 13, 2023
@m-akinc m-akinc self-assigned this Aug 1, 2023
m-akinc added a commit that referenced this issue Sep 1, 2023
## 🤨 Rationale

Fixes #1293
Part of #1014 
Adding design token ("lang") for locale and honoring that token's value
when formatting dates in the date-text column.

## 👩‍💻 Implementation

- introduced "lang" design token with dynamic default that uses the
page's `lang` property, if valid, otherwise uses "en-US"
- new `DocumentElementLang` singleton watches page element's `lang`
property
- added `lang` property to theme provider which sets design token value
- using design token value when creating formatter used by date-text
column
- added new validation flag to theme provider that is set when the
locale is malformed
- setting 'en-US' locale for all date-text unit tests (which they were
already assuming)
- added unit tests

## 🧪 Testing

Unit tests pass (even when system locale is something other than 'en').

## ✅ Checklist

- [x] I have updated the project documentation to reflect my changes or
determined no changes are needed.

---------

Co-authored-by: mollykreis <[email protected]>
Co-authored-by: Jesse Attas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs investigation Further research is needed to identify solution
Projects
Development

Successfully merging a pull request may close this issue.

2 participants