Text does not get translated with _ if such text is inside a macro
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:
- Python version: 3.8.5
- Jinja version: 2.11.3
- Babel version: 2.8.0
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.
- Python version: 3.8.7
- Jinja version: 2.11.2
- Babel version: 2.9.0
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.