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

tornado.locale.Locale.get_closest does not find locales according to RFC #1955

Open
dwt opened this issue Feb 20, 2017 · 0 comments
Open

tornado.locale.Locale.get_closest does not find locales according to RFC #1955

dwt opened this issue Feb 20, 2017 · 0 comments
Labels

Comments

@dwt
Copy link

dwt commented Feb 20, 2017

Hi there,

we noticed this problem when we translated our app to 'zh_Hant' where 'Hant' is a script not a region, but Locale.get_closest treats it as it treats region codes and tries to find it capitalized.

This is AFAIK wrong on multiple levels. First rfc4647 says that

    Language tags and thus language ranges are to be treated as case-
    insensitive: there exist conventions for the capitalization of some
    of the subtags, but these MUST NOT be taken to carry meaning.
    Matching of language tags to language ranges MUST be done in a case-
    insensitive manner.

Language tags are to my understanding the whole string, (so 'zh_Hant' for us) and thus all matching should happen at least case insensitive.

But that code is also making lots of assumptions and does some parsing which probably is wrong (though I'm not deep enough in the RFC to say so).

Some things that could be done here (in ascending order of severance of code changes)

  • Add a fallback that tries to find the original argument without trying to change it, so there is at least a workaround for programmers who know what they're doing.
  • Change matching to be case insensitive. This would be more in line with the RFC, but also has more probability of introducing new problems for existing users.
  • Use a propper locale parsing library (e.g. Babel )
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