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

locale doesn't preserve territory and doesn't do error handling #3279

Open
spaceone opened this issue Jun 11, 2023 · 0 comments
Open

locale doesn't preserve territory and doesn't do error handling #3279

spaceone opened this issue Jun 11, 2023 · 0 comments
Labels

Comments

@spaceone
Copy link
Contributor

spaceone commented Jun 11, 2023

>>> import tornado.locale
>>> tornado.locale.load_gettext_translations('/usr/share/locale', 'foo')

>>> tornado.locale.get('de').code
'de'
>>> tornado.locale.get('de_DE').code
'de'
>>> tornado.locale.get('de-DE').code
'de'
>>> tornado.locale.get('de-DE').__dict__.keys()
dict_keys(['ngettext', 'gettext', 'code', 'name', 'rtl', 'translations', '_months', '_weekdays'])

→ there is no territory information stored. Please store it additionally.
I provide a de locale directory which is valid for de-DE and de-AT. I want to pass the exact value back which the client provided in the Accept-Language header.

>>> tornado.locale.get('de')
<tornado.locale.GettextLocale object at 0x7f4adae9ca58>
>>> tornado.locale.get('de-DE')
<tornado.locale.GettextLocale object at 0x7f4adae9ca58>
>>> tornado.locale.get('de_DE')
<tornado.locale.GettextLocale object at 0x7f4adae9ca58>
>>> tornado.locale.get('de_DE-foo')
<tornado.locale.CSVLocale object at 0x7f4ade726e80>

→ why doesn't this raise some exception?

see also #1955 and #1858

Edit: there is some assertion error. Maybe this can also be changed into a real exception?

>>> tornado.locale.Locale.get('en_US')
<tornado.locale.CSVLocale object at 0x7f333cc632e8>
>>> tornado.locale.Locale.get('en')                                                                                                                                                                                                           
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/tornado/locale.py", line 264, in get
    assert code in _supported_locales
AssertionError
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