fix: fall back to the default locale when formatting with an unknown locale - #1800
Open
abhijeet117 wants to merge 1 commit into
Open
fix: fall back to the default locale when formatting with an unknown locale#1800abhijeet117 wants to merge 1 commit into
abhijeet117 wants to merge 1 commit into
Conversation
|
|
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.
Summary
Formatting a DateTime with an unsupported locale option fell back to the system locale instead of Settings.defaultLocale, because Intl silently resolves unknown locales to the system one. Following the discussion in #1366, the default locale is now passed to Intl as a backup locale when it differs from the requested one, so Intl prefers it over the system locale. The formatter cache key includes the locales list, so changes to Settings.defaultLocale take effect immediately.
Testing
Reproduced on master: with Settings.defaultLocale = "fr", dt.toFormat("LLLL", { locale: "zz" }) returned the system-locale month name instead of "mai". Added regression tests in toFormat.test.js covering the fallback and the behavior after changing Settings.defaultLocale. The full jest suite matches the clean-master baseline on Windows, with both new tests passing.
Checklist
Fixes #1366