Code Monkey home page Code Monkey logo

accept-language-parser's People

Contributors

andyroyle avatar arnoldzokas avatar carlosrocha avatar greenkeeperio-bot avatar lledey avatar matteofigus avatar nickbalestra avatar pbazydlo avatar piperchester avatar sheerun avatar tlhunter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

accept-language-parser's Issues

Not supporting header containing plain language-country only, e.g., `en-US`

Hi,

if you switch language on an iPad (via Settings / General / Language & Region / iPad Language), Safari might not send the usual language-country + language combination (e.g., en-US,en) but a plain language-country only (e.g., en-US) without language fallback. Unfortunately, this is not supported by the accept language parser.

Expected behavior:

var parser = require("accept-language-parser"); // version 1.4.1
var language = parser.pick(['en', 'fr'], 'en-US'); // 'en'

Actual behavior:

var parser = require("accept-language-parser"); // version 1.4.1
var language = parser.pick(['en', 'fr'], 'en-US'); // null

Not sure if this should be supported.
Thank you.

.pick ignores quality?

I'm trying to use incoming HTTP headers to serve up the most appropriate translation of a site, and it seems like .pick is exactly what I need, but it's not respecting the quality value of headers. When I run this:

parser.pick(["en", "nl"], "en-GB,nl;q=0.5"

I would expect it to return en, but it's giving me nl. Is this on purpose or would you like a PR to fix it?

Cannot cope with multi-part region codes

As the README says,

Cannot cope with multi-part region codes, i.e. 'az-AZ-Cyrl' will be treated as 'az-AZ'

Example:

require('accept-language-parser').parse('zh-Hans-CN')[0].region // 'Hans'

Setting a default

Hi,

Is it possible to have a default language fallback - for example, if the accept-language header doesn't contain one of our supported languages it uses a default. For example:

parser.pick(['en-GB'], 'en-US'); // can it return en-GB not null

Thanks.

Example for `loose` option is not correct

In your README it states that parser.pick(['fr', 'en'], 'en-GB,en-US;q=0.9,fr-CA;q=0.7,en;q=0.8'); would return "fr". But that's not correct IMO:

> parser.pick(['fr', 'en'], 'en-GB,en-US;q=0.9,fr-CA;q=0.7,en;q=0.8');
'en'
> parser.pick(['fr', 'en'], 'en-GB,en-US;q=0.9,fr-CA;q=0.7,en;q=0.8', { loose: true });
'en'

I'd say this is indeed the expected behaviour, because there are to en with q=1 which should have preference over the fr locale.

Bonus: The README's example for the loose option is missing the { loose: true }.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.