locale doesn't preserve territory and doesn't do error handling
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- python
- Domain
- localization
Research direction
Start in locale.py and reproduce the Accept-Language examples for de, de-DE, de_DE, and de_DE-foo. Trace how locale codes are normalized and validated. Done means supported locales retain the requested territory where applicable, while invalid locale requests produce a real exception instead of an assertion failure.
Written by the indexing model from the issue text.
Description
>>> 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
- Dominant language
- Python
- Stars
- 22.2k
- Forks
- 5.6k
- Avg merge
- 3h 42m
- Merged PRs (30d)
- 16
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tornadoweb/tornado
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
tornadoweb/tornado#3701 · 1 comment ·
-
httpserver
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
tornadoweb/tornado#1050 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
tornadoweb/tornado#3728 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 64/100
tornadoweb/tornado#3651 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 50/100
tornadoweb/tornado#3616 · 2 comments ·
All issues in tornadoweb/tornado
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100