langtag-utils
lookup(tags, ranges, defaultValue = 'en')
Find the most appropriate language tag that matches a language priority list.
navigatorLanguages()
Retrieves the language information saved in window.navigator backwards compatible.
parse(tag)
Parses the language tag and returns an object with all available information.
Installation
npm install --save langtag-utils
How to use
; const whiteList = 'de' 'en';const fallbackLng = 'de';const detectedLng = ; ... console;/*{ 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, }}*/ ...