-
Notifications
You must be signed in to change notification settings - Fork 107
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
Consider making ResolveLocale return the normalized requested locale instead of the available locale #830
Comments
To be specific, from the canonicalized list of requested locales. Intl.NumberFormat.supportedLocalesOf('EN-us') → ['en-US'] |
icu::datetime::DateTimeFormatter expects a single DataLocale to construct a new formatter object, but For example: new Intl.DateTimeFormat(["nds", "ksh", "de"], {localeMatcher: "lookup", month: "long"}).format(0) Can have the following outputs: (Assuming
Note: CLDR has data for all three locales, but For example: new Intl.DateTimeFormat("co", {localeMatcher: "best fit", month: "long"}).format(0) Can have the following outputs: (Assuming
Note: CLDR has data for If there is more than one requested locale and the For example: new Intl.DateTimeFormat(["co", "es"], {localeMatcher: "best fit"}).resolvedOptions().locale Assuming Using the Browsers are using This leads to returning non-optimal results in some cases, but nobody has ever complained about this: The available locales list from new Intl.DateTimeFormat("de-Latn-AT", {localeMatcher: "lookup", month: "long"}).format(0)
(*) And
Conceptually the available locale describes that useful/expected results can be generated. For example when requesting I wonder if the main issue is just that there's confusion what is meant by resolved locale? The resolved locale doesn't describe the locale where the underlying date is defined. For example when requesting
Whether or not root fallback is acceptable depends on the Intl service constructor, used options, and the kind of fallback. For example a root fallback for I'm not sure what you mean when mentioning "fallback to DefaultLocale". Root locale fallback is different from default locale fallback. When this is about the default locale fallback in LookupMatcher, it's detectable when the default locale fallback will be used by first calling into LookupSupportedLocales.
When LookupMatcher doesn't find an available locale and steps 3-5 are executed:
Which entry from And because I saw this mentioned in the Matrix logs (here and here): No browser actually implements the So it's basically it's the reverse situation when compared to
V8 has some WIP code to support the |
Good observation. This may also rise to the level of a use case for a developer caring about the difference between an availableLocale and a requestedLocale.
An issue here is that the default icu_datagen fallback mode is to save space by stripping locales that fall back to a parent containing the same data. ICU4C does the same thing, but it retains memory of a certain locale being present in the form of an empty resource file. icu_datagen has a mode, "hybrid", that disables this stripping (at the cost of slightly larger binary size: no data is duplicated but the lookup structure is larger). Assuming we retain the current behavior in ECMA-402, it would be a requirement for implementers using ICU4X to build their data in hybrid mode.
I find it interesting that all the browsers codify the availableLocales behavior. Do they do this because 402 makes the availableLocales list observable? One could pass in thousands of locales and eventually piece together the list. ICU4X implements a fallback which is not the lookup matcher; the "de-Latn-AT" case is one that ICU4X specifically tries to solve. So, an engine wanting a lookup matcher would need to implement this on top of ICU4X, and the "best fit" matcher would be to simply use the ICU4X fallback machinery. |
I think there's still some confusion about what the resolved locale should be. // Uses the <dateFormatItem> data from "de.xml". Only the <month> data is used from "de_AT.xml"
console.log(new Intl.DateTimeFormat("de-AT", {localeMatcher: "lookup", month: "long"}).resolvedOptions().locale);
// Uses the <dateFormatItem> data from "de.xml". <day> is also used from "de.xml".
console.log(new Intl.DateTimeFormat("de-AT", {localeMatcher: "lookup", weekday: "long"}).resolvedOptions().locale); This should print Is it possible to store the locales processed by |
Yes, this is doable and should be easy to implement, if we think this is the best path forward. |
Conclusion: keep the status quo. Too potentially disruptive and motivation not strong enough right now to make a change. Reconsider if we hear stronger motivation. |
The concept of an "available locale" is not always well defined. For example, DateTimeFormat might have data in more locales for certain numbering systems and calendars than others, or more locales for the inner NumberFormat than for the datetime patterns. Also, engines like ICU4X do not directly expose the resolved locale information.
Currently the ECMA-402 specification requires that the resolved locale in
resolvedOptions()
be an entry from theavailableLocales
list, a list which is never directly exposed to the client. However,supportedLocalesOf()
echoes back entries from therequestedLocales
list.The use cases for
resolvedOptions().locale
are not completely clear, but a few might beI think both of these cases can be served by making
ResolveLocale
return an entry fromrequestedLocales
instead of an entry fromavailableLocales
.CC @hsivonen
ICU4X issue: unicode-org/icu4x#3906
The text was updated successfully, but these errors were encountered: