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

intl-localematcher: Incorrect locale information provided with '*' #4405

Closed
tkrotoff opened this issue Apr 29, 2024 · 4 comments
Closed

intl-localematcher: Incorrect locale information provided with '*' #4405

tkrotoff opened this issue Apr 29, 2024 · 4 comments
Labels

Comments

@tkrotoff
Copy link

tkrotoff commented Apr 29, 2024

Which package?

@formatjs/intl-localematcher

Describe the bug

import { match } from "@formatjs/intl-localematcher"

match(['*'], ['en'], 'en');

// => Throws "RangeError: Incorrect locale information provided"
@tkrotoff tkrotoff added the bug label Apr 29, 2024
@longlho
Copy link
Member

longlho commented Apr 29, 2024

'*' is not a valid locale

@tkrotoff
Copy link
Author

Yes

new Intl.Locale('*') => RangeError: Incorrect locale information provided

However

HTTP header Accept-Language can be * cf https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language#sect1

So you would expect code like this to work:

import { match } from "@formatjs/intl-localematcher"

// Derived from HTTP header Accept-Language
// For example using https://github.com/jshttp/negotiator
// const preferredLocales = new Negotiator({ headers }).languages();
const preferredLocales = ['*'];

const availableLangs = ['nl', 'fr', 'de'];
const defaultLang = availableLangs[0];

match(preferredLocales, availableLangs, defaultLang);
// => 'nl' (defaultLang)

@longlho
Copy link
Member

longlho commented Apr 29, 2024

Conceptually your client expects any locale, so there's no need to locale match you can just return any of the locales you support.

@longlho
Copy link
Member

longlho commented Apr 29, 2024

Again, the locale we expect is Unicode Locale Identifier and * is not a valid locale

@tkrotoff tkrotoff closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2024
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