feat(web-core): implement locale support and fix pluralize#1427
Merged
Conversation
- Add optional `locale` to `SurfaceModel` and `DataContext`. - Update `pluralize`, `formatNumber`, and `formatCurrency` to use context locale instead of hardcoded 'en-US'. - Remove `.passthrough()` from `PluralizeApi` schema. - Add tests for pluralize with Welsh locale covering all categories.
- Cache `Intl.NumberFormat` and `Intl.PluralRules` instances to improve efficiency. - Add try-catch block to `FormatNumberImplementation` to prevent crashes on invalid locales, falling back to `toFixed` or `String`. - Add try-catch block to `PluralizeImplementation` for safety.
…tions.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
ditman
approved these changes
May 13, 2026
Collaborator
ditman
left a comment
There was a problem hiding this comment.
Minor nitpicks. We should have an issue (if it doesn't exist already) to track improving the types of the arguments to function calls?
- Add tests for values 0 and 1 falling back to 'other' when specific categories are missing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds locale support to
DataContextandSurfaceModelinweb-core, and updatespluralize,formatNumber, andformatCurrencyto use the resolved locale instead of hardcoding 'en-US'. It also includes removing.passthrough()fromPluralizeApiand adding tests for Welsh locale.Changes
surface-model.ts: Added optionallocaleparameter toSurfaceModelconstructor.data-context.ts: Addedlocalegetter toDataContextthat delegates tosurface.locale.basic_functions.ts: UpdatedPluralizeImplementation,FormatNumberImplementation, andFormatCurrencyImplementationto usecontext.locale.basic_functions_api.ts: Removed.passthrough()fromPluralizeApischema for stricter validation.basic_functions.test.ts: UpdatedcreateTestDataContextto support passing a locale, and added tests forpluralizewith the Welsh locale (cy) covering all 6 categories.CHANGELOG.md: Added entries under "Unreleased".Impact & Risks
localeparameter is optional and defaults toundefined. If not provided, theIntlAPIs will fall back to the runtime's default locale, maintaining current behavior for existing usage.Testing
basic_functions.test.ts.npm run testinrenderers/web_core. All 258 tests passed.Fixes #1385