opentable / accept-language-parser Goto Github PK
View Code? Open in Web Editor NEWIt parses the accept-language header from an HTTP request
Home Page: https://www.npmjs.com/package/accept-language-parser
License: MIT License
It parses the accept-language header from an HTTP request
Home Page: https://www.npmjs.com/package/accept-language-parser
License: MIT License
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.
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?
thank you anyone for any suggestion :)
Thanks for this package, very useful and a nice simple clean interface.
Android 7.0 introduced a smarter heuristic for locale matching that searches child locales of a root language locale before trying a new language preference. Full details with samples are here ...
https://developer.android.com/guide/topics/resources/multilingual-support
Would be wonderful to support this improved algorithm in your pick() function.
Please add TypeScript declarations!
Edit: @types/accept-language-parser
package.
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'
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.
I'm going to use it in the new npm website. :)
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 }
.
[This is a super opinionated nit] if we're not using them, can we disable them in project settings?
Love the util, great work!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.