JSRuntime::setDefaultLocale doesn't set some locales correctly
Categories
(Core :: JavaScript: Internationalization API, defect)
Tracking
()
People
(Reporter: Sasha, Unassigned)
References
Details
While working on bug 1968951 I discovered the setting of a default locale with JSRuntime::setDefaultLocale doesn't work correctly for some locales:
- three letter languages like:
ast,yue,apc,gsware reset to en-GB innew Intl.DateTimeFormat().resolvedOptions().locale. If callJS_GetDefaultLocale(context)after setting the locale, it returns the correct value. Also, if I callnew Intl.DateTimeFormat("ast").resolvedOptions()it returnsast(the same foryue,gsw, but not forapcwhere I geten-DE). - some locales values get truncated:
de-DE-1996becomesde-DE,sl-Roza-biske -> sl,ca-ES-valencia -> ca-ES,sl-1994 -> sl,zh-Latn-CN-variant1-a-extend1-u-co-pinyin-x-private-zh-Latn-CN-variant1 -> zn(expectedzh-Latn-CN-variant1) but the results are consistent with passing the locale tonew Intl.DateTimeFormat(locale).resolvedOptions().locale. - some locales values get truncated only with override:
th-TH-u-nu-thai -> th-TH,en-US-u-ca-gregory -> en-US-u-ca-gregory, but e.g., newIntl.DateTimeFormat("th-TH-u-nu-thai").resolvedOptions().localereturnsth-TH-u-nu-thai. So looks like in this case numberingSystem is not set.
I've also tried canonizing the locale before passing it to JS_SetDefaultLocale, but that didn't seem to help:
nsAutoCString lang = NS_ConvertUTF16toUTF8(GetLanguageOverride());
mozilla::intl::Locale loc;
if (mozilla::intl::LocaleParser::TryParse(lang, loc).isOk() && loc.Canonicalize().isOk()) {
Vector<char, 32> locale;
intl::VectorToBufferAdaptor buffer(locale);
loc.ToString(buffer);
JS_SetDefaultLocale(runtime, JS_EncodeStringToASCII(context, JS_NewStringCopyN(context, locale.begin(), locale.length())).get());
}
Comment 1•10 months ago
|
||
There are various requirements for the default locale used in ECMA-402 which are relevant here:
- The default locale must be supported by all Intl constructors:
js> Intl.Collator.supportedLocalesOf(["ast", "yue", "apc", "gsw"])
[]
js> Intl.DateTimeFormat.supportedLocalesOf(["ast", "yue", "apc", "gsw"])
["ast", "yue", "gsw"]
Intl.Collator doesn't support any of the requested locales, so we can't use them as the ECMA-402 default locale. (Note: We may remove the Intl.Collator requirement as part of bug 1937541.)
-
Variant subtags like in
de-DE-1996are (implicitly) removed because the actually supported locale isde-DE. -
Unicode extension subtags are removed per ECMA-402.
The code to select the ECMA-402 default locale is here.
| Reporter | ||
Comment 2•10 months ago
|
||
Alright, just to confirm that I understood it right: there is nothing we can/should do here, the default locale override works as expected and that's acceptable by the specification. Sounds right?
Comment 3•10 months ago
|
||
Yes, that's right.
V8 doesn't handle invalid default locales, which could explain why Chrome-based tests show a different behaviour. https://issues.chromium.org/issues/42207567.
| Reporter | ||
Comment 4•10 months ago
|
||
Alright, thanks a lot for the feedback!
I'm going to close the bug as wontfix.
Description
•