Add navigator.locales to expose additional locale details #3046
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.
In existing browser implementations, navigator.languages seems
to expose the basics of a locale--language, possibly region and
script. However, there are additional locale-related settings
which are taken as parameters by ECMA 402 and which fit into
BCP 47 language tags.
It is possible that just changing the value of navigator.languages
could break existing sites. For example, localizations which
are selected based on the exact value of navigator.language would
find an unknwon language if a Unicode extension tag is appended.
For this reason, rather than attempting to expose those options
via BCP 47 Unicode extension tags, this patch adds a navigator.locales
property. navigator.locales is a FrozenArray of Intl.Locale objects.
Intl.Locale is a new proposal in TC39 which makes it easier to
parse and manipulate language tags.
This PR is just intended to start a conversation. There are a few open questions:
navigator.locales
, rather than saying that the core of Intl defaults to those values, makes it a bit factored out.navigator.locale
for ergonomics, though there's not much point when you can usenavigator.locales[0]
.navigator.locales[0].language
to get the main language. A downside is that this feature is blocked on Intl.Locale making it through TC39.I'd be interested in any feedback you would have.