Skip to content

Follow imports in Jinja templates #1262

@GergelyKalmar

Description

@GergelyKalmar

I'm wondering if I could get Babel to somehow follow macros to their definition in Jinja templates when extracting messages.

Let's say I have a Jinja template file in my project like so:

{% import 'some_library/components/many_macros.html.j' as many_macros %}
{{ many_macros.test_localization()) }}

And the macro (which sits in a different project/package) is like so:

{% macro test_localization(text=_('color')) %}
  <p><b>Content:</b> {{ text }}</p>
{% endmacro %}

Currently Babel does not seem to pick up the string from the default value in the macro definition, despite the Jinja template calling out to it. Is there a way to get 'color' be added to the list of strings that need to be translated without adding all the gettext-marked strings in some_library/components/many_macros.html.j file as well?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions