Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
frankthelen opened this issue Dec 18, 2017 · 5 comments

Comments

@frankthelen
Copy link

frankthelen commented Dec 18, 2017

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.

@matteofigus
Copy link
Contributor

@frankthelen I think the first argument of the pick is supposed to be a full language and you are providing the abbreviated format.

var language = parser.pick(['en-US', 'fr-FR'], 'en-US') // en-US
var language2 = parser.pick(['en-US', 'fr-FR'], 'en') // en-US

@matteofigus
Copy link
Contributor

Closing because of lack of interest. Please reopen if needed.

@frankthelen
Copy link
Author

frankthelen commented Jan 25, 2018

Well, strictly speaking, en is not an abbreviation. It means English but not country or region-specific. So, if I request en-US but there is only en available, it should give me en as a reasonable fallback even if it's not the US variant of the language.

But anyway, as far as I know, it affects only iPads that are (sometimes?) not sending correct full accept-language headers. They are sending en-US instead of correctly en-US,en;... in some cases. Haven't seen this behavior in any other browser/device.

@matteofigus
Copy link
Contributor

@ArnoldZokas what's your opinion on that?

@matteofigus matteofigus reopened this Jan 25, 2018
@sheerun
Copy link
Contributor

sheerun commented Mar 19, 2018

In my use case I need to pick one of non-prefixed languages given prefixed accept-language. There should be at least an option to have this behavior :)

matteofigus added a commit that referenced this issue Mar 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants