【问题标题】:Blocktrans correctly written in django template用 django 模板正确编写的 Blocktrans
【发布时间】:2015-03-27 09:06:08
【问题描述】:

我希望我的 django 模板变量可以翻译。我为此使用了 {% blocktrans %}。

这段代码是否正确并且可以优化。我的意思是写得更好?循环或类似的东西。

{% for obj in objects %}
    {% blocktrans with obj.user as user and obj.country as country and obj.b_day as b_day %}
    <tr>
        <td>{{ user }}</td>
        <td>{{ country }}</td>
        <td>{{ b_day }}</td>
    </tr>
    {% endblocktrans %}
{% endfor %}

【问题讨论】:

  • 你试过了吗?结果哪里ok?
  • 它工作正常。我想知道是否可以写得更好。
  • 既然你问是因为你不喜欢你的代码中的某些东西。这是什么?就我个人而言,我不喜欢在翻译中包含太多 html 标签

标签: django translation django-templates django-i18n


【解决方案1】:

嗯,我怀疑你的代码不能正常工作。无论如何,简单的{% trans %} 标签看起来好多了:

{% for obj in objects %}
    <tr>
        <td>{% trans obj.user %}</td>
        <td>{% trans obj.country %}</td>
        <td>{% trans obj.b_day %}</td>
    </tr>
{% endfor %}

【讨论】:

    猜你喜欢
    • 2010-12-21
    • 1970-01-01
    • 1970-01-01
    • 2015-04-01
    • 2017-09-04
    • 2017-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多