Closed Bug 1975931 Opened 10 months ago Closed 10 months ago

JSRuntime::setDefaultLocale doesn't set some locales correctly

Categories

(Core :: JavaScript: Internationalization API, defect)

defect

Tracking

()

RESOLVED WONTFIX

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, gsw are reset to en-GB in new Intl.DateTimeFormat().resolvedOptions().locale. If call JS_GetDefaultLocale(context) after setting the locale, it returns the correct value. Also, if I call new Intl.DateTimeFormat("ast").resolvedOptions() it returns ast (the same for yue, gsw, but not for apc where I get en-DE).
  • some locales values get truncated: de-DE-1996 becomes de-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 (expected zh-Latn-CN-variant1) but the results are consistent with passing the locale to new 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., new Intl.DateTimeFormat("th-TH-u-nu-thai").resolvedOptions().locale returns th-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());
}

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-1996 are (implicitly) removed because the actually supported locale is de-DE.

  • Unicode extension subtags are removed per ECMA-402.

The code to select the ECMA-402 default locale is here.

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?

Flags: needinfo?(andrebargull)

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.

Flags: needinfo?(andrebargull)

Alright, thanks a lot for the feedback!
I'm going to close the bug as wontfix.

Status: NEW → RESOLVED
Closed: 10 months ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.