accept-language
parses HTTP Accept-Language header and returns a matched defined language.
npm install accept-language --save
// var acceptLanguage = require('accept-language');
import acceptLanguage from 'accept-language';
acceptLanguage.languages(['en-US', 'zh-CN']);
console.log(acceptLanguage.get('en-GB,en;q=0.8,sv'));
/*
'en-US'
*/
If you are using Express server please use the middleware express-request-language.
Define your language tags ordered in highest priority comes first fashion. The language tags must comply with BCP47 standard.
acceptLanguage.languages(['en-US', 'zh-CN']);
Get the most likely language given an Accept-Language
string. In order for it to work you must set all your languages first.
acceptLanguage.get('en-GB,en;q=0.8,sv');
Tingan Ho @tingan87
MIT