0
votes

Django 1.11

settings.py

INSTALLED_APPS = [
...
    'general',
    'general_frame',
...
]
LANGUAGE_CODE = 'ru-RU'

USE_I18N = True

USE_L10N = True

general/models.py

class GeneralModel(models.Model):
    """Sharing common features of models."""

    title = models.CharField(max_length=200,
                             null=False,
                             blank=False,
                             default="",
                             verbose_name=_("title"))

general_frame/models.py

class GeneralFrame(GeneralModel):

    DOCUMENT = 'D'
    PHOTO = 'P'
    PHOTO_DOCUMENT_CHOICES = ((None, '----'),
                              (DOCUMENT, _('document')),
                              (PHOTO, _('photo')),)
    type = models.CharField(max_length=1, choices=PHOTO_DOCUMENT_CHOICES,
                            blank=False,
                            null=False,
                            default="---",
                            verbose_name=_('type'))

I have executed makemessages and compilemessages. The structure is as follows:

Project structure:

├── general
│   ├── locale
│   │   └── ru_RU
│   │       └── LC_MESSAGES
│   │           ├── django.mo
│   │           └── django.po
├── general_frame
│   ├── locale
│   │   └── ru_RU
│   │       └── LC_MESSAGES
│   │           ├── django.mo
│   │           └── django.po

The problem is: everything in GeneralFrame is translated, bot GeneralModel is not translated. I mean that document, photo and type are translated. But title is not translated.

I made messages, checked .po files and recompiled messages again several times.

Could you give me a kick here?

1
What is _ there? Can you please add the import lines to your code?Gokhan Sari
Gökhan Sarı, thank you very much for the kick. In "general" it was ugettext_lazy. If you organize an answer, I'd gladly accept it. Just two words "Check import".Michael

1 Answers

0
votes

So, my wild guess was true eh? :)

For django to discover your translated string, you need to make sure you wrap the string with one of django's translation methods, you can find about it on docs. Make sure you imported required translation method like this:

from django.utils.translation import ugettext_lazy as _

# now you can use _('your string'), and django will discover your string