Question

I am using Flask, jinja together with Mustachjs.

In order to get the job done I am using the {% raw %} tag.

Now, it is a multi-languages application and I use Babel.

How can I do :

 {% raw %}
  <script id="details" type="text/template">

        <table class="table" >

        <thead>
        <tr>
                <th>**{{gettext('col1')}}</th>
                <th>**{{gettext('col2')}}</th>
                <th>**{{gettext('col6')}}</th> 

        </tr>
        </thead>
        <tbody>
        {{#skyrsla}}
                <tr>
                        <td> {{index}}</td>
                        <td> {{nafn}}</td>
                        <td> {{mean_growth_index}}</td>
                </tr>
        {{/skyrsla}}
        </tbody>

        </table>
</script>
{% endraw %}

Since it is between raw tags, the Babel extension does not detect {{gettext('col1')} Is there a way to alter the configuration of Babel.

My actual configuration looks like :

[python: **.py]
[jinja2: **/templates/**.html]
extensions=jinja2.ext.autoescape,jinja2.ext.with_
Was it helpful?

Solution

Simply end your raw blocks between calls to gettext:

{% raw %}
  <script id="details" type="text/template">

        <table class="table" >

        <thead>
        <tr>
                <th>**{% endraw %}{{gettext('col1')}}{% raw %}</th>
                <th>**{% endraw %}{{gettext('col2')}}{% raw %}</th>
                <th>**{% endraw %}{{gettext('col6')}}{% raw %}</th> 

        </tr>
        </thead>
        <tbody>
        {{#skyrsla}}
                <tr>
                        <td> {{index}}</td>
                        <td> {{nafn}}</td>
                        <td> {{mean_growth_index}}</td>
                </tr>
        {{/skyrsla}}
        </tbody>

        </table>
</script>
{% endraw %}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top