Skip to content
BCP47 language negotiation
TypeScript
Branch: master
Clone or download
Tingan Ho
Latest commit 91a9743 Oct 21, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Library
Source Fixes language specificity and case-insensitivity Oct 21, 2017
Tests
Typings
.editorconfig
.gitignore Fixes #23, Revert language matching algorithmen Jun 11, 2017
.npmignore Removes Build/Tests dir from npm Sep 6, 2016
.travis.yml
LICENSE
README.md
package.json
tsconfig.json Fixes language specificity and case-insensitivity Oct 21, 2017

README.md

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 language tags must comply with BCP47 standard.

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

acceptLanguage.get(String acceptLanguageString);

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');

Maintainer

Tingan Ho @tingan87

License

MIT

You can’t perform that action at this time.