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

Accept-Language Negotiation example does not make sense to me #31

Closed
alanhogan opened this issue Dec 5, 2014 · 3 comments
Closed

Accept-Language Negotiation example does not make sense to me #31

alanhogan opened this issue Dec 5, 2014 · 3 comments
Labels

Comments

@alanhogan
Copy link

In the example of Accept-Language Negotiation, the example is:

negotiator = new Negotiator(request)

availableLanguages = 'en', 'es', 'fr'

// Let's say Accept-Language header is 'en;q=0.8, es, pt'

negotiator.languages()
// -> ['es', 'pt', 'en']

negotiator.languages(availableLanguages)
// -> ['es', 'en']

language = negotiator.language(availableLanguages)
// -> 'es'

Now, I see that the user's most-preferred language is English (en), and English is an availableLanguage, so why would we resolve to Spanish (es)?

@dougwilson
Copy link
Contributor

Now, I see that the user's most-preferred language is English (en), and English is an availableLanguage, so why would we resolve to Spanish (es)?

The header en;q=0.8, es, pt means that es = 1, pt = 1, and en = 0.8, making en (English) the least preferred. The lack of the q signifies 1, which is greater than 0.8.

@dougwilson
Copy link
Contributor

@alanhogan
Copy link
Author

Ah, thanks. Definitely missed that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants