pallets / jinja

A very fast and expressive template engine.
https://jinja.palletsprojects.com
BSD 3-Clause "New" or "Revised" License
10.08k stars 1.59k forks source link

Text does not get translated with _ if such text is inside a macro #1375

Open qlands opened 3 years ago

qlands commented 3 years ago

I have the following Macro:

{% macro display_errors(errors,modal=false) %}
    {% if modal == false %}
        {% for error in errors %}
            <div class="alert alert-danger alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                {{ error }}.
            </div>
        {% endfor %}
    {% else %}
        {% if errors|length > 0 %}
            <div class="alert alert-danger alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                {{ _('The last action reported errors') }}. <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#error_modal">{{ _('See errors') }}</button>
            </div>
        {% endif %}
    {% endif %}
{% endmacro %}

Which I use with a code like:

{% import 'dashboard/macros/form.jinja2' as form %}
...
{{ form.display_errors(errors,true) }}

Even though I have the text "The last action reported errors" in the .po files and the rest of the App translates properly, the message inside the macro does not get translated.

#: formshare/templates/dashboard/macros/form.jinja2:17
msgid "The last action reported errors"
msgstr "La última acción reportó errores"

Environment:

peteris-zealid commented 3 years ago

Translating inside a macro works for me. Maybe you forgot to recompile the .po to .pm (this happens to me a lot)

I used gettext instead of _ but that should not make a difference.

qlands commented 3 years ago

I recompile the .po into .mo . All my translations use _

I tried by adding a new translation string to the macro file for example title="{{ _('Close') }}" and other just the same in an element outside the macro.

After python setup.py extract_messages, python setup.py update_catalog, translating the string, and python setup.py compile_catalog the string inside the macro does not translate but the one outside does.