-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
tornado.locale.Locale.get_closest() not getting closest match #1858
Comments
Bump - not sure why this has not been fixed. Currently Tornado does this:
That last value should be True |
This fixes the situation where the browser returns a two character locale, such as de, but the supported_locales de_DE.
It seems header locale format vs unix locale format is being mixed. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language#Directives
In the other hand,
I would expect |
Yeah, this is some old code that makes some questionable design decisions. It's not very principled in how it handles different locale formats.
You can already do that: |
The tornado.locale.Locale.get_closest() (and as such by extension tornado.locale.get) function is a bit malformed. It tries to match two character language codes directly against the frozenset in which the five character language codes are stored, which obviously fails. As a result it can only get exact matches and will return the default locale when using two character codes.
Specifically this part:
I wrote the following simple function in my own code to bypass this problem but I bet someone else can write it a bit nicer into the intended function:
The text was updated successfully, but these errors were encountered: