Find the most appropriate language tag that matches a language priority list.
Retrieves the language information saved in window.navigator backwards compatible.
Parses the language tag and returns an object with all available information.
npm install --save langtag-utils
import { lookup, navigatorLanguages, parse } from 'langtag-utils';
const whiteList = ['de', 'en'];
const fallbackLng = 'de';
const detectedLng = lookup(whiteList, navigatorLanguages(), fallbackLng);
...
console.log(parse('en-Latn-GB-boont-r-extended-sequence-x-private'));
/*
{
langtag: {
language: {
language: 'en',
extlang: [],
},
script: 'Latn',
region: 'GB',
variant: ['boont'],
extension: [
{
singleton: 'r',
extension: ['extended', 'sequence'],
},
],
privateuse: ['private'],
},
privateuse: [],
grandfathered: {
irregular: null,
regular: null,
}
}
*/
...