【问题标题】:How to specify context of translation in Django {% trans %} {% blocktrans %}?如何在 Django {% trans %} {% blocktrans %} 中指定翻译上下文?
【发布时间】:2013-05-20 21:27:57
【问题描述】:

Documentation of Djangotrans 和 blocktrans 模板标签也支持上下文标记。 但它没有说明如何做到这一点?

你能帮忙标记翻译上下文吗,因为我有一些词有多种含义。

在 Python 中我可以这样做:

pgettext("month name", "May")
pgettext("verb", "May")

如何在 Django 模板中指定翻译上下文?

{% blocktrans %}May{% endblocktrans %}

【问题讨论】:

    标签: django internationalization django-templates django-i18n


    【解决方案1】:

    在其特定段落的末尾进行了解释:

    https://docs.djangoproject.com/en/dev/topics/i18n/translation/#trans-template-tag

    {% trans %} 还支持使用 context 关键字的上下文标记:

    {% trans "May" context "month name" %}
    

    https://docs.djangoproject.com/en/dev/topics/i18n/translation/#blocktrans-template-tag

    {% blocktrans %} 还支持使用 context 关键字的上下文标记:

    {% blocktrans with name=user.username context "greeting" %}Hi {{ name }}{% endblocktrans %}
    

    【讨论】:

      【解决方案2】:
      {% blocktrans context "month name" %}May{% endblocktrans %}
      

      【讨论】:

        猜你喜欢
        • 2013-07-11
        • 2012-10-01
        • 2015-10-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-26
        • 1970-01-01
        相关资源
        最近更新 更多