#34297 closed Bug (invalid)
ValueError: invalid token in plural form: EXPRESSION when adding new language
Reported by: | Azat | Owned by: | nobody |
---|---|---|---|
Component: | Utilities | Version: | 4.1 |
Severity: | Normal | Keywords: | gettext, i18n, l10n |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
I used this guide on [stackoverflow](https://stackoverflow.com/questions/12946830/how-to-add-new-languages-into-django-my-language-uyghur-or-uighur-is-not-su) to setup my language:
Here is my code:
# ======== support locale ========= # https://stackoverflow.com/questions/12946830/how-to-add-new-languages-into-django-my-language-uyghur-or-uighur-is-not-su LOCALE_PATHS = [BASE_DIR / "locale"] LANGUAGES = ( ('en', _('English')), ('tr', _('Turkish')), ('uly', gettext_noop('Uyghur')), # ('uay', gettext_noop('Uyghur')), ) EXTRA_LANG_INFO = { 'uly': { 'bidi': False, # right-to-left 'code': 'uly', 'name': 'Uyghur', 'name_local': 'Uyghur', # unicode codepoints here }, }
When i try to run the code, it gives me this error:
Internal Server Error: /uly/admin/ Traceback (most recent call last): File "/Users/azat/Developer/Django/izdinish/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) File "/Users/azat/Developer/Django/izdinish/venv/lib/python3.10/site-packages/django/utils/deprecation.py", line 135, in __call__ response = self.process_request(request) File "/Users/azat/Developer/Django/izdinish/venv/lib/python3.10/site-packages/django/middleware/locale.py", line 35, in process_request translation.activate(language) File "/Users/azat/Developer/Django/izdinish/venv/lib/python3.10/site-packages/django/utils/translation/__init__.py", line 181, in activate return _trans.activate(language) File "/Users/azat/Developer/Django/izdinish/venv/lib/python3.10/site-packages/django/utils/translation/trans_real.py", line 298, in activate _active.value = translation(language) File "/Users/azat/Developer/Django/izdinish/venv/lib/python3.10/site-packages/django/utils/translation/trans_real.py", line 287, in translation _translations[language] = DjangoTranslation(language) File "/Users/azat/Developer/Django/izdinish/venv/lib/python3.10/site-packages/django/utils/translation/trans_real.py", line 166, in __init__ self._add_local_translations() File "/Users/azat/Developer/Django/izdinish/venv/lib/python3.10/site-packages/django/utils/translation/trans_real.py", line 226, in _add_local_translations translation = self._new_gnu_trans(localedir) File "/Users/azat/Developer/Django/izdinish/venv/lib/python3.10/site-packages/django/utils/translation/trans_real.py", line 193, in _new_gnu_trans return gettext_module.translation( File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/gettext.py", line 602, in translation t = _translations.setdefault(key, class_(fp)) File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/gettext.py", line 261, in __init__ self._parse(fp) File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/gettext.py", line 439, in _parse self.plural = c2py(plural) File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/gettext.py", line 183, in c2py result, nexttok = _parse(_tokenize(plural)) File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/gettext.py", line 116, in _parse nexttok = next(tokens) File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/gettext.py", line 93, in _tokenize raise ValueError('invalid token in plural form: %s' % value) ValueError: invalid token in plural form: EXPRESSION [27/Jan/2023 09:23:38] "GET /uly/admin/ HTTP/1.1" 500 135230 /Users/azat/Developer/Django/izdinish/izdinish/settings.py changed, reloading.
Change History (7)
comment:1 by , 22 months ago
Description: | modified (diff) |
---|
comment:2 by , 22 months ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:3 by , 22 months ago
Summary: | raise ValueError('invalid token in plural form: %s' % value) , ValueError: invalid token in plural form: EXPRESSION when adding new language → ValueError: invalid token in plural form: EXPRESSION when adding new language |
---|
comment:4 by , 7 months ago
I used to be able to add any unsupported language to Django (so and yue) (and I even deployed to prod yesterday), now I can't even run makemessages, and runserver does not start, with the exact same message. Probably it is because gettext got updated on homebrew and it does something differently.
I think we should still be able to add unsupported languages without any hustle, like we used to do. (I just had to add the language to locale directory and I didn't even have to change settings.py). I know, for a proper bug I should be able to pin down the exact version numbers, but it seems to be wrong since django 3, and I was just lucky to have been using the right version of gettext.🤷🏻
follow-up: 6 comment:5 by , 7 months ago
I'm not sure how this should be considered a regression given nothing points at Django being misconfigured here.
Until someone can pinpoint how Django might be to blame and what exactly the problem is then everything seems to point at a gettext
/ Python problem.
follow-up: 7 comment:6 by , 7 months ago
Replying to Simon Charette:
I'm not sure how this should be considered a regression given nothing points at Django being misconfigured here.
Until someone can pinpoint how Django might be to blame and what exactly the problem is then everything seems to point at a
gettext
/ Python problem.
To be honest, one important thing you can do before commenting on other people's ticket is simply try and check if that is the case. Python not displaying enough information but it dose not mean, you saw the whole world from that console info.
The problem I mentioned 14 months ago, has been resolved by "Adding the language to django officially". That was the solution, yes, except your language is being added to the django source code, the problem above occurs when you try to add a new one yourself.
I ma not sure, from which version Django behaves like this, but in earlier versions, you could actually add a new language yourself, by changing proper settings and providing local translation files.
comment:7 by , 7 months ago
Replying to Azat:
To be honest, one important thing you can do before commenting on other people's ticket is simply try and check if that is the case. Python not displaying enough information but it dose not mean, you saw the whole world from that console info.
While we appreciate your input, and while we understand that you may feel frustrated by the response, the sentence above is confrontational. We kindly remind you to maintain a respectful and constructive tone in your communications. Please follow the Django Code of Conduct when commenting on tickets.
I ma not sure, from which version Django behaves like this, but in earlier versions, you could actually add a new language yourself, by changing proper settings and providing local translation files.
It has been said that Django does not support the feature you are describing (adding new custom language), and that if it has worked before, it was by chance. The proper procedure at this stage was completed, which is to close this ticket as invalid following the ticket triaging process.
Everyone is welcomed to seek further help in the user support channels.
Please don't use Trac as a support channel. Closing per TicketClosingReasons/UseSupportChannels.