formatjs / formatjs

The monorepo home to all of the FormatJS related libraries, most notably react-intl.

Home Page:https://formatjs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@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