views:

46

answers:

2

I'm writing an application, which will be used in several languages: 'en', 'de', 'fr', 'es' and 'pl'. I provided translation strings for every string that needs to be translated, I prepared the translation files and compiled them.

Then, I set the LANGUAGES variable and added the LocaleMiddleware in settings.py.

The problem is, when I enter the page, say /admin/, the strings provided as strings are translated properly (I use 'pl' in Accept-Language), but the strings in models and forms (like labels and verbose_names) are displayed in the LANGUAGE_CODE language (when I change the language code, the models are translated).

Anyone got an idea, what's wrong?

A: 

have you tried

from django.utils.translation import ugettext as _

verbose_names = _("Eggs")
kusut
No. This is probably exactly what went wrong. ugettext() translates strings immediately when it is invoked, into the language that is defined at that time. For models and forms, this happens only once at initialization time. In such contexts one should use ugettext_lazy() instead, which creates an object that performs the translation at the time the value is requested.See also http://docs.djangoproject.com/en/1.2/topics/i18n/internationalization/#lazy-translations
Bernd Petersohn
A: 

I've been using ugettext instead of ugettext_lazy. Remember to use the latter for django's strings!

halish