2
votes

A very strange behavior appears to happen in my django project.

I marked every important string in my project as translatable with ugettext_lazy like in the documentation

When I'm using these variables in my templates some of them are translated, with the matching string from the translation-file but others don't.

I also tried the instructions and hints given in How to setup up Django translation in the correct way? and https://docs.djangoproject.com/en/dev/topics/i18n/translation/#how-django-discovers-language-preference

I also tried to switch a bit around between ugettext and ugettext_lazy to see some effect. I ran

python manage.py compilemessages -a -l de -v3  
python manage.py compilemessages

after each time I tries something else.

THe effect is still present, that the first few entries that are used in views and templates are translated probably but every entry after the first message string that appears only in a python file is not translated. regardless if it appears to be in a template, a python file or both.

Example:

#: backend/forms.py:18 backend/views.py:129 backend/views.py:134
#: backend/views.py:1274 backend/views.py:1275
#: backend/templates/backend/index.html:31
msgid "username"
msgstr "Benutzername"

#: backend/forms.py:19 core/templates/core/tables/employees_table.html:6
msgid "first name"
msgstr "Vorname"

#: backend/forms.py:20 core/templates/core/tables/employees_table.html:7
msgid "last name"
msgstr "Nachname"

#: backend/forms.py:21
msgid "mail address"
msgstr "E-Mailadresse"

So username, first name, last name are translated perfectly according to my browser-settings, but mail address isn't translated, even if it is used in a simple string in the template like {% trans "mail address" %} (right asides of {% trans "username" %})

Because of the working translations for the first two strings I assume, that the error is not somewhere in my settings.

1
First make sure you make proper use of ugettext_lazy for everything that is executed at module load time like models and forms fields definitions etc - cf docs.djangoproject.com/en/dev/topics/i18n/translation/…. If you import alias ugettext or ugettext_lazy to _() (which is a common practice, make sure you don't rebind this name later. Also remember that you have to restart your server after the call to compilemessages. Finally, check for fuzzy translations in your translation files - fuzzy translations are in fact not translated. - bruno desthuilliers
I checked the points you mentioned. But, even if I introduce a complete new string to test translation it does not get translated either. - BlueSapphire
Sorry but that's all we (well, I at least) can suggest to help without having the project installed locally. - bruno desthuilliers
Sadly, I guess so too. I hope I got this solved somehow. - BlueSapphire

1 Answers

0
votes

Maybe your folders are on the wrong pattern. It must be on ll_CC, like pt_BR or es_MX.

I had this problem too: https://stackoverflow.com/a/31889066/2418887