Socket
Socket
Sign inDemoInstall

accept-language

Package Overview
Dependencies
1
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    accept-language

HTTP Accept-Language parser for node


Version published
Weekly downloads
138K
decreased by-15.22%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

accept-language Build Status

NPM

accept-language parses HTTP Accept-Language header and returns the most likely language or a consumable array of languages.

Installation:

npm install accept-language --save

Usage:

var acceptLanguage = require('accept-language');
accepLanguage.languages(['en-US', 'zh-CN']);
console.log(accepLanguage.get('en-GB,en;q=0.8,sv'));
/*

'en-US'

*/
var language = acceptLanguage.parse('en-GB,en;q=0.8,sv');
console.log(language);
/*

[
  {
    value: 'en-US',
    language: "en",
    region: "US",
    quality: 1.0
  }
];

*/

L10ns is an internationalization workflow and formatting tool. This library was specifically built for L10ns. L10ns is a very good alternative to Gettext and all of it's tooling support–XGettext, PoEdit, custom libraries etc.

API

acceptLanguage.languages(Array languageTags);

Define your language tags ordered in highest priority comes first fashion. The language tags must comply with BCP47 standard. The BCP47 language tag consist of at least the following subtags:

  1. A language subtag (en, zh).
  2. A script subtag (Hant, Latn).
  3. A region subtag (US, CN).

Then language tag has the following syntax:

language[-script][-region]

Which makes the following language tags en, en-US and zh-Hant-TW all BCP47 compliant. Please note that the script tag refers to language script. Some languages use two character sets instead of one. Chinese is a good example of having two character sets instead of one–it has both traditional characters and simplified characters. And for popular languages that uses two or more scripts please specify the script subtag, because it can make an i18n library fetch more specific locale data.

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'));
acceptLanguage.parse(String acceptLanguageString);

Parse an Accept-Language string and get a consumable array of languages. In order for it to work you must set all your language tags first.

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

Maintainer

Tingan Ho @tingan87

License

MIT

Keywords

FAQs

Last updated on 16 Feb 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc