Przemek
Przemek

Reputation: 647

Django command makemessages does not generate string marked for translations for files in templates directory

I have project in Django==2.2.12

and this is part of my settings:

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [os.path.join(BASE_DIR, "templates")],
        "APP_DIRS": True,
        "OPTIONS": {
            "context_processors": [
                "django.template.context_processors.debug",
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.contrib.messages.context_processors.messages",
                "django.template.context_processors.static",
            ],
        },
    },
]

LANGUAGE_CODE = "pl"

TIME_ZONE = "Europe/Warsaw"

USE_I18N = True

USE_L10N = True

USE_TZ = False

LANGUAGES = (
    ('pl', gettext('Polish')),
    ('en', gettext('English')),
)

When I execute:

django-admin makemessages --locale=en

It generates .po files with string to translate in locale directory from .py files but it completly skips .txt files that are located in my templates directory. For example it does not generate string for translation for my text.txt file with following content:

{% load i18n %} 
{% blocktranslate %}
string to translate
{% endblocktranslate %}

Upvotes: 0

Views: 355

Answers (1)

Zourka
Zourka

Reputation: 1

  1. Make sure to use {%trans 'your string %}
  2. Use this command to update .po files: python manage.py makemessages -l ar --no-wrap --no-location
  3. Remove #fuzzy if it's above what you want to translate
  4. Run python manage.py compilemessages

I hope this helps!

Upvotes: 0

Related Questions