在Django模板中,这两者之间有什么区别呢?

{% blocktrans %}My Text{% endblocktrans %}

{% trans 'My Text' %}

解决方法


Django Docs

Trans模板标签

The {% trans %} template tag translates either a constant string (enclosed in single or >double quotes) or variable content:

使用Trans标签,您仅限于单个常量字符串或变量.所以你必须使用

{# These Would Work! #}
title>{% trans "This is the title." %}</title>
<title>{% trans myvar %}</title>

但不能使用

{%trans "This is my title {{ myvar }}" %}

Blocktrans模板标签

Contrarily to the trans tag,the blocktrans tag allows you to mark complex sentences
consisting of literals and variable content for translation by making use of placeholders:

使用Blocktrans,这种代码是可行的:

{% blocktrans with book_t=book|title author_t=author|title %}
       This is {{ book_t }} by {{ author_t }}
    {% endblocktrans %}

所以Blocktrans将允许你在你的输出中更复杂一些.

但是从字面上回答你的问题:没有多少.除了演示风格,两者都将作为字符串“我的文本”发送到翻译器

dawei

【声明】:淮南站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。