niwinz / django-jinja

Simple and nonobstructive jinja2 integration with Django.
http://niwinz.github.io/django-jinja/latest/
BSD 3-Clause "New" or "Revised" License
363 stars 102 forks source link

makemessages ignores `{% trans %}` block #314

Open Eroica opened 6 months ago

Eroica commented 6 months ago

Hi,

I'm afraid I must be doing something wrong, but with the following setup, I cannot get makemessages to parse anything in {% trans %}...{% enddtrans %} blocks:

pyproject.toml:

[tool.poetry.dependencies]
python = "^3.11"
Django = "^5.0.6"
django-jinja = "^2.11.0"

settings.py:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'newstyle_gettext': True,
            "extensions": DEFAULT_EXTENSIONS + [
            ],
        },
    },
]

Then a sample template file in /subapp/templates/subapp/index.jinja:

{{ _("This works") }}

{% trans %}This gets ignored{% endtrans %}

{% blocktrans %}This also works{% endblocktrans %}

I then run poetry run python manage.py makemessages -l en -e html,txt,py,jinja which produces this .po file:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-05-14 16:41+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: .\subapp\templates\subapp\index.jinja:1
msgid "This works"
msgstr ""

#: .\subapp\templates\subapp\index.jinja:5
msgid "This also works"
msgstr ""

My problem is that I would like to use {% trans %}... for more complex strings, and I cannot use blocktrans because then Jinja complains about an unknown tag. Any idea what could be wrong? If required, I'll upload a whole sample project.