At first I created this question, but it looks like I have two separate problems. To reduce the amount of code I have created a new project. In this project I create an app. I have added only one model:
from django.db import models
from django.utils.translation import gettext_lazy as _
class MyModel(models.Model):
name = models.CharField(
verbose_name=_('Field name'),
max_length=20
)
In the settings.py
file I put the following:
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
...
]
...
LANGUAGE_CODE = 'uk'
TIME_ZONE = 'Europe/Kiev'
USE_I18N = True
USE_TZ = True
So after I made the migrations and created a superuser, I created the locale
folder in the project root and tried to run this command:
django-admin makemessages -l uk
It successfully generated the .po
file where I was able to add my translation:
#: .\myapp\models.py:7
msgid "Field name"
msgstr "Назва"
Then I tried the command:
django-admin compilemessages -l uk
And it generated a .mo
file.
So everything looks fine, but when I go to the admin page and open my model, the field name is not translated. The interface is in Ukrainian, but in the model I see
Have I missed anything? Thank you for your help!