Skip to content
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

Region detection algorithm not always working properly #16

Closed
xdev1 opened this issue Nov 18, 2022 · 2 comments
Closed

Region detection algorithm not always working properly #16

xdev1 opened this issue Nov 18, 2022 · 2 comments

Comments

@xdev1
Copy link

xdev1 commented Nov 18, 2022

Great Britain allows two different valid time formats:

  • The 24-hour time format: 14:34
  • The 12-hour time format: 2:34 pm

Intl uses the 24-hour time format for locale en-GB.
If you want to use the 12-hour time format for GB then you have to use locale en-GB-u-hc-h12.
Please find here a litte demo.

So now assume you are using locale en-GB-u-hc-h12. Then this line

const regionCode = this.lang().length > 2 ? this.lang().toLowerCase() : ''; // e.g. en-gb

will fail to detect the proper code (which should be "en-gb").

Please find here a little demo that shows one case where that bug leads to wrong i18n behavior.

It might be a good idea to use new Intl.Locale('en-GB-u-hc-h12') (see here and here).

@claviska
Copy link
Member

Nice catch. I've updated it so use Intl.Locale() and published 3.0.2. Thanks!

@claviska
Copy link
Member

Just a heads up — 3.0.2 detects the region correctly but fails to prepend the language code to it. 🤦🏻‍♂️

Please use 3.0.3 instead, which works as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants