3

我正在使用 Flask、jinja 和 Mustachjs。

为了完成工作,我使用了 {% raw %} 标签。

现在,它是一个多语言应用程序,我使用 Babel。

我能怎么做 :

 {% 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 %}

由于是在原始标签之间,所以 Babel 扩展并没有检测到 {{gettext('col1')} 有没有办法改变 Babel 的配置。

我的实际配置如下:

[python: **.py]
[jinja2: **/templates/**.html]
extensions=jinja2.ext.autoescape,jinja2.ext.with_
4

1 回答 1

3

只需在调用之间结束您的原始块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 %}
于 2012-07-26T20:48:30.780 回答