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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.