【问题标题】:mustache, babel and gettext小胡子、通天塔和 gettext
【发布时间】:2012-07-26 14:00:41
【问题描述】:

我正在使用 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_

【问题讨论】:

    标签: python flask jinja2 mustache python-babel


    【解决方案1】:

    只需在调用 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 %}
    

    【讨论】:

      猜你喜欢
      • 2011-08-29
      • 2012-01-03
      • 1970-01-01
      • 2015-06-28
      • 1970-01-01
      • 1970-01-01
      • 2013-02-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多