#1233 closed defect (invalid)
i18n does not work for win32
Reported by: | Jaroslaw Zabiello | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Core (Other) | Version: | |
Severity: | critical | Keywords: | i18n win32 |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I try to test http://www.djangoproject.com/documentation/i18n/ but it does not work for win32. If I add. I created all correct .po & .mo files . Django always displays the content of msgid instead of msgstr. I tried (according to mentioned manual) the following code to settings.py file:
LANGUAGES = ( ('de', _('German')), ('en', _('English')), )
But... after that I have problems with starting the server:
D:\i18n-test\myproject>python manage.py runserver Traceback (most recent call last): File "manage.py", line 4, in ? import settings # Assumed to be in the same directory. File "D:\i18n-test\myproject\settings.py", line 72, in ? LANGUAGES = ( NameError: name '_' is not defined
Hmmn, if I have changed it to the following:
from django.utils.translation import gettext as _ LANGUAGES = ( ('de', _('German')), ('en', _('English')), )
...another exception raises:
D:\i18n-test\myproject>manage.py server Traceback (most recent call last): File "D:\i18n-test\myproject\manage.py", line 4, in ? import settings # Assumed to be in the same directory. File "D:\i18n-test\myproject\settings.py", line 72, in ? LANGUAGES = ( File "c:\opt\python24\lib\site-packages\Django-0.91-py2.4.egg\django\utils\translation.py", line 242, in gettext from django.conf import settings File "c:\opt\python24\lib\site-packages\Django-0.91-py2.4.egg\django\conf\settings.py", line 34, in ? raise EnvironmentError, "Could not import %s '%s' (is it on sys.path?): %s" % (ENVIRONMENT_VARIABLE, me.SETTINGS_MODULE, e) EnvironmentError: Could not import DJANGO_SETTINGS_MODULE 'myproject.settings' (is it on sys.path?): cannot import name settings
Note:
See TracTickets
for help on using tickets.
I18n does work. The problem you see is caused by an import loop:
you should not import any django modules in your settings file
since many of them depend on your project settings in some way.
The LANGUAGES tuple is created in django's global_settings.py file
and that that seems to be the only place you can add more languages.
For 'de' and any languages from this list
you do not need to change a thing, just set LANGUAGE_CODE to 'de' or
add LocaleMiddleware to your MIDDLEWARE_CLASSES and use it to set the
preferred language.