加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Django i18n blocktrans vs trans

发布时间:2020-12-16 23:31:41 所属栏目:Python 来源:网络整理
导读:在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 qu
在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将允许你在你的输出中更复杂一些.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读