[go: up one dir, main page]

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

shouldPolyfill('fr') returns incorrect value in intl-displaynames@6.6.2 #4267

Closed
gzurbach opened this issue Nov 13, 2023 · 8 comments
Closed
Labels

Comments

@gzurbach
Copy link
gzurbach commented Nov 13, 2023

Which package?

intl-displaynames

Describe the bug

After upgrading intl-displaynames from 6.6.1 to 6.6.2 I cannot use the library with locale fr. Same issue arises with 6.6.3 and above.

To Reproduce

This works as expected:

npm install @formatjs/intl-displaynames@6.6.1

const languageNames = new Intl.DisplayNames(['fr'], { type: 'language' });

However, this fails:

npm install @formatjs/intl-displaynames@6.6.2

const languageNames = new Intl.DisplayNames(['fr'], { type: 'language' });

Error message:

Error: Missing locale data for 
@gzurbach gzurbach added the bug label Nov 13, 2023
@gzurbach gzurbach changed the title Missing locale data in intl-displaynames@6.6.3 Missing locale data in intl-displaynames@6.6.2 Nov 13, 2023
@longlho
Copy link
Member
longlho commented Nov 13, 2023

can u provide a codesandbox?

@gzurbach
Copy link
Author

Sure thing: https://codesandbox.io/s/javascript-forked-h5d7yz?file=/src/index.js

It seems like the issue comes from this particular call:

import { shouldPolyfill } from "@formatjs/intl-displaynames/should-polyfill";

const foo = shouldPolyfill("fr");

With 6.6.1 I am getting foo = "fr" which is expected.
With 6.6.2 I am getting foo = "br" which is the short code for a regional French language (breton). This is not correct.

Because of this bug my app is not loading @formatjs/intl-displaynames/locale-data/fr.

@gzurbach
Copy link
Author

Long story short, I had to replace:

const foo = shouldPolyfill("fr");
await import(`@formatjs/intl-displaynames/locale-data/${foo}`);

by:

const foo = shouldPolyfill("fr");
await import(`@formatjs/intl-displaynames/locale-data/fr`);

@gzurbach gzurbach changed the title Missing locale data in intl-displaynames@6.6.2 shouldPolyfill('fr') returns incorrect value in intl-displaynames@6.6.2 Nov 15, 2023
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Dec 15, 2023
@gzurbach
Copy link
Author

As far as I know this issue is not resolved, and should not be closed.

@github-actions github-actions bot removed the Stale label Dec 16, 2023
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Jan 15, 2024
@longlho longlho removed the Stale label Jan 16, 2024
@longlho
Copy link
Member
longlho commented Jan 16, 2024

kk this issue is due to the list of supportedLocales is assumed to be ordered which for polyfills they aren't. Will fix soon.

@longlho
Copy link
Member
longlho commented Jan 16, 2024

For posterity, the problem is the list of supported locales have both br & fr but was sorted alphabetically. fr - br has a match score of 250 but because fr's index was more than 250 below br, the penalty kicks in and knock it down to 259.

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

No branches or pull requests

2 participants