node package manager

accept-language

accept-language Build Status

NPM

accept-language parses HTTP Accept-Language header and returns a matched defined language.

Installation:

npm install accept-language --save

Usage:

// 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'
 
*/

Usage with Express:

If you are using Express server please use the middleware express-request-language.

API

acceptLanguage.languages(Array languageTags);

Define your language tags ordered in highest priority comes first fashion. The first language will act as a default language in case of no match. The language tags must comply with BCP47 standard.

acceptLanguage.languages(['en-US', 'zh-CN']);

acceptLanguage.get(String acceptLanguageString);

Get a matched language given an Accept-Language string. In case of no match, the default language or null will be returned.

acceptLanguage.get('en-GB,en;q=0.8,sv');

Maintainer

Tingan Ho @tingan87

License

MIT