Bug 197213 - [INTL] en-NZ locale defaults to en-US locale instead of using en-NZ
Summary: [INTL] en-NZ locale defaults to en-US locale instead of using en-NZ
Status: VERIFIED CONFIGURATION CHANGED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-23 14:59 PDT by Daniel Compton
Modified: 2020-04-15 09:59 PDT (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Compton 2019-04-23 14:59:28 PDT
When using Intl.DateTimeFormat/Intl.NumberFormat in the New Zealand locale (en-NZ), if you use Intl.DateTimeFormat() or Intl.DateTimeFormat("default"), JavaScriptCore resolves the locale to the en-US locale. This only seems to happen for New Zealand. When macOS is using the United Kingdom, USA, or Australia locales, JavaScriptCore returns the expected locale.

Reproduction steps:

* Open Language & Region in System Preferences
* Change the Region to the region under test
* Open a Safari web-page and the Web Inspector
* Run this statements in the Console:

[new Intl.DateTimeFormat("default").resolvedOptions().locale,
new Intl.DateTimeFormat().resolvedOptions().locale,
new Intl.DateTimeFormat().format(new Date())]

Current output:

// In the Australia region:
=> ["en-AU", "en-AU", "24/04/2019"]

// In United Kingdom
=> ["en-GB", "en-GB", "24/04/2019"]

// In United States
=> ["en-US", "en-US", "4/24/2019"]

// In New Zealand (this one shows the problem)
=> ["en-US", "en-US", "4/24/2019"]

Expected output for New Zealand:

["en-NZ", "en-NZ", "24/04/2019"]

JavaScriptCore does correctly format the output if the en-NZ locale is specified:

[new Intl.DateTimeFormat("en-NZ").resolvedOptions().locale,
new Intl.DateTimeFormat("en-NZ").format(new Date())]
=> ["en-NZ", "en-US", "24/04/2019"]

I would expect that the default locale returned by JavaScriptCore matches the system locale, especially where JavaScriptCore does support that locale like en-NZ. If en-NZ is not supported, then I would probably expect to default to en-AU, and failing that en-GB. Both of those locales are more similar to en-NZ than en-US is.

Tested in
Safari Technology Preview: Release 80 (Safari 12.2, WebKit 14608.1.16)
Safari: Version 12.1 (14607.1.40.1.4)

Other notes:

I tested this briefly in Chrome and Firefox for the NZ region. Chrome returns en-NZ as the default locale, Firefox has the same behaviour as Safari
Comment 1 Alexey Proskuryakov 2019-04-26 20:18:14 PDT
I suspect that JavaScriptCore ends up using bundle localization for default locale, which actually feels correct - it's not great when browser UI and webpage content use different languages and formats. Safari happens to have "en", "en_AU" and "en_GB" localizations, but no "en_NZ".

> If en-NZ is not supported, then I would probably expect to default to en-AU, and failing that en-GB. Both of those locales are more similar to en-NZ than en-US is.

That's a good idea. Unlike the main issue reported here, such logic definitely wouldn't be in WebKit though, it would be in Foundation. WebKit relies on underlying system to resolve locales, so Foundation would need to decide that en_AU should be used instead of the default. Please feel welcome to file a bug for Apple to consider via https://bugreport.apple.com
Comment 2 Daniel Compton 2019-04-28 11:25:57 PDT
Thanks for the feedback, it makes sense how this is happening. I've opened rdar://50280505 for the Foundation enhancement. Feel free to close this issue if there's no further actions to take available in WebKit.
Comment 3 Daniel Compton 2019-04-28 11:27:00 PDT
Also, I forgot to mention that I really appreciated the full explanation of what is happening. Thanks!
Comment 4 Alexey Proskuryakov 2019-04-29 10:43:44 PDT
Leaving open for the JSC folks to confirm whether they agree that this is expected behavior.
Comment 5 Andy VanWagoner 2019-04-30 15:22:36 PDT
JSC looks up the default locale from its embedder (Foundation or WebCore), falling back to libicu's default locale, and ultimately to "en" if none of those others had a value.

Resolving to a "closest" default locale is not specified in the ECMA 402 spec, but I agree "en-US" isn't a great fit for "en-NZ".

I can't speak to where the logic ultimately would need to change (Foundation, WebCore, or elsewhere in Safari), but it's not currently in JSC.

Does `navigator.language` agree with `Intl.DateTimeFormat().resolvedOptions().locale`?
Comment 6 Daniel Compton 2019-05-02 15:42:48 PDT
> Does `navigator.language` agree with `Intl.DateTimeFormat().resolvedOptions().locale`?

Yes, with macOS in the NZ Locale, Safari shows:

> [navigator.language, Intl.DateTimeFormat().resolvedOptions().locale]
< ["en-US", "en-US"]
Comment 7 Andy VanWagoner 2019-05-02 19:55:03 PDT
(In reply to Daniel Compton from comment #6)
> > Does `navigator.language` agree with `Intl.DateTimeFormat().resolvedOptions().locale`?
> 
> Yes, with macOS in the NZ Locale, Safari shows:
> 
> > [navigator.language, Intl.DateTimeFormat().resolvedOptions().locale]
> < ["en-US", "en-US"]

Ok, good. Intl apis are behaving as expected, then.
Comment 8 Ross Kirsling 2020-04-14 18:15:46 PDT
Closing as I'm seeing `new Intl.DateTimeFormat("en-NZ").resolvedOptions().locale` return "en-NZ" in STP 104 on Catalina.

Please reopen if there's still an issue here.
Comment 9 Daniel Compton 2020-04-14 21:21:40 PDT
I think this is fixed, though there may be a regression in STP?

Running this on Safari 13.1, macOS 10.15.4 in NZ region:

[new Intl.DateTimeFormat("default").resolvedOptions().locale,
new Intl.DateTimeFormat().resolvedOptions().locale,
new Intl.DateTimeFormat().format(new Date()),
navigator.language]

=> ["en-AU", "en-AU", "15/04/2020", "en-au"] 

Running the same in STP Release 104 (Safari 13.2, WebKit 15610.1.8.3) returns:

=> ["en-US", "en-US", "4/15/2020", "en-us"]
Comment 10 Alexey Proskuryakov 2020-04-15 09:59:55 PDT
Could you please file a new bug about this? I did't see the same problem with Russian, although I found a different regression, bug 210554.

In the new bug, please provide the output of "defaults read -g AppleLanguages; defaults read -g AppleLocale" on your machine.