Using `ugettext` in a Django Field Definition

In my file, models.pyI define the field in the model as follows:

description = models.CharField(
    max_length=40,
    default=_('Bla bla bla'),
)

Now _there is django.utils.translation.ugettext, and I want to use the Hebrew translation 'Bla bla bla', which is equal, as the default value 'בלה בלה בלה'. (The website is only in Hebrew.) The string is correctly translated into the message file. But when I start the Django admin and create a new object, I see English 'Bla bla bla'in the field. I assume that English is the active language when compiling a module models.py. How can I solve this and make it Hebrew?

I know that one solution would be to give up ugettextand just write Hebrew inside the Python module, but I prefer to avoid this to prevent hell coding.

+3
source share
2 answers

Try ugettext_lazy

https://docs.djangoproject.com/en/1.3/topics/i18n/internationalization/#lazy-translation

Always use lazy translations in the Django model.

+1
source

ugettext just marks strings as translatable. He does not do any translation for you. You need to create language files (.mo and .po), and then set the value of the LANGUAGE_CODE parameter. Read the Django internationalization and localization documentation for more details .

+1
source

All Articles