accept-language
accept-language
parses HTTP Accept-Language header and returns the most likely language tag or a consumable array of language tags.
Installation:
npm install accept-language --save
Usage:
var acceptLanguage = require('accept-language');
accepLanguage.languageTags(['en-US', 'zh-CN']);
console.log(accepLanguage.get('en-GB,en;q=0.8,sv'));
var language = acceptLanguage.parse('en-GB,en;q=0.8,sv');
console.log(language);
Recommended usage with L10ns:
L10ns is internationalization workflow and formatting tool. This library was specifically built for L10ns.
API
accepLanguage.languageTags(Array languageTags);
Define your language tags in highest priority comes first. The language tags must comply with BCP47 standard. I.e. all language tags en
, en-US
and zh-Hant-TW
are working.
acceptLanguage.languageTags(['en-US', 'zh-CN']);
accepLanguage.get(String acceptLanguageString);
Get the most likely language tag given an Accept-Language
string. In order for it to work you must set all your language tags first.
acceptLanguage.get('en-GB,en;q=0.8,sv'));
accepLanguage.parse(String acceptLanguageString);
Parse an Accept-Language
string and get a consumable array. In order for it to work you must set all your language tags first.
acceptLanguage.get('en-GB,en;q=0.8,sv'));
License
MIT