H
H
Hukyl2021-03-08 00:21:47
Django
Hukyl, 2021-03-08 00:21:47

Why doesn't translation work in Django templates?

Python Django 3.0 project.
I want to translate the text both in the code and in the template.

There are all the necessary presets:

1. 2.USE_I18N = True

LANGUAGES = [('uk', 'Ukrainian'), ('en', 'English')]

3.4 .LANGUAGE_CODE = 'uk'
'OPTIONS': {'context_processors': ['django.core.context_processors.i18n', ...]

5.
MIDDLEWARE = ['django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware', ...]

6.7 .INSTALLED_APPS = [..., 'master', 'administrator']
LOCALE_PATHS = [
    os.path.join(PROJECT_ROOT, 'apps', 'master', 'locale'),
    os.path.join(PROJECT_ROOT, 'apps', 'administrator', 'locale'),
]

8. In templates, the first tag is `{% load i18n %}`
9. All templates have a translation tag (`{% translate "some text" %}`)
10. After that, I enter the commandpath('i18n/', include('django.conf.urls.i18n')),
django-admin makemessages --locale=uk --extension=html,txt,py


The file django.podoes not contain any lines from the templates, and when starting the server and entering the page with the translation, it throws an error:

Invalid block tag on line 32: 'translate', expected 'endblock'. Did you forget to register or load this tag?


What does the translation from the code have and is successfully translated.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question