@formatjs/intl-localematcher documentation is wrong... incorrect order
UROjQ6r80p opened this issue · comments
@formatjs/intl-localematcher documentation is wrong...
According to https://formatjs.io/docs/polyfills/intl-localematcher/ this should be the correct order:
const { match } = require("@formatjs/intl-localematcher")
// order here should not matter
const websiteLocalesUnordered = [
'pt',
'pt-br',
];
// order here should not matter
const websiteLocalesUnordered2 = [
'pt-br',
'pt'
];
// taken from header 'accept-language'
const userLanguagesOrdered = [
'pt-br'
];
const fallbackLng = 'en';
// Wrong
console.log(match(userLanguagesOrdered, websiteLocalesUnordered, fallbackLng)) // => 'pt'
console.log(match(userLanguagesOrdered, websiteLocalesUnordered2, fallbackLng)) // => 'pt-br'
// Correct
console.log(match(websiteLocalesUnordered, userLanguagesOrdered, fallbackLng)) // => 'pt-br'
console.log(match(websiteLocalesUnordered2, userLanguagesOrdered, fallbackLng)) // => 'pt-br'
This is correct order:
match(websiteLocalesUnordered, userLanguagesOrdered, fallbackLng)
There is no clear indication which is which, nextjs in their examples also uses incorrect order https://nextjs.org/docs/app/building-your-application/routing/internationalization.
I think it should be clearly stated which part is a list of app/website available locales (unordered) and which is derived from the browser/user device (ordered)
nvm, my mistake