Bug 1975931 Comment 0 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

While working on bug 1968951 I discovered the setting of a default locale with [JSRuntime::setDefaultLocale](https://searchfox.org/mozilla-central/source/js/src/vm/Runtime.cpp#511) 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.
While working on bug 1968951 I discovered the setting of a default locale with [JSRuntime::setDefaultLocale](https://searchfox.org/mozilla-central/source/js/src/vm/Runtime.cpp#511) 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());
}
```

Back to Bug 1975931 Comment 0