Wttr.in: Language order not respected correctly

Created on 10 May 2018  Â·  7Comments  Â·  Source: chubin/wttr.in

It turns out that if you provide a header with language options,

e.g. curl -H 'Accept-Language: en-US,en;q=0.9,nl;q=0.8' wttr.in/~Portland

The system provides a response in the least-preferred language, e.g.:

Weerbericht voor: Portland

    \  /       Gedeeltelijk bewolkt
  _ /"".-.     59 °F
    \_(   ).   → 4 mph
    /(___(__)  9 mi
               0.0 in

This is incorrect. The first language in the list is the one that the site should choose for localization.

Most helpful comment

Slight correction, the language with the highest q value should be chosen. (Which most browsers will make the first in the list, but it's not mandatory.)

All 7 comments

Slight correction, the language with the highest q value should be chosen. (Which most browsers will make the first in the list, but it's not mandatory.)

This is happening for me too and I came to the same conclusion.
My request headers:

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8,he;q=0.7
Cache-Control: max-age=0
Connection: keep-alive
Host: wttr.in
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36

And then the page displays in Hebrew, even though this is the least preferred language in my request.
image

FYI, Hebrew is also mostly broken on the result page. May I suggest pulling back RTL languages until the page can properly format them?

wttr.in currently does not respect q parameter. What's more interesting is that copying the functions reveal they are working properly (tested both on Python 2 and 3):

$ python
>>> # functions pasted here, with exception of `if lang in SUPPORTED_LANGS`...
>>> _find_supported_language(_parse_accept_language("en-US,en;q=0.9,nl;q=0.8"))
'en'

Does Flask reorder header content or what?

The problem here seems to be that "en" has a somewhat of a "special status": It's the "default" language when no other language is specified, but not int he list of supported languages (SUPPORTED_LANGS). When "en" appears in the "Accept-Language" header, it is completely ignored by _find_supported_language().

This looks like a simple fix: Either add "en" to the list of supported languages (don't know the side effects of it), or special case "en" in _find_supported_language().

Seems a duplicate of #116

The problem is fixed by @talyian in #304. Please test

Was this page helpful?
0 / 5 - 0 ratings

Related issues

097115 picture 097115  Â·  6Comments

cjwelborn picture cjwelborn  Â·  6Comments

532910 picture 532910  Â·  7Comments

a0s picture a0s  Â·  8Comments

m0lmk picture m0lmk  Â·  5Comments