您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Django i18n blocktrans vs trans

5b51 2022/1/14 8:23:04 python 字数 1763 阅读 616 来源 www.jb51.cc/python

在Django模板中,这两者之间有什么区别呢? {% blocktrans %}My Text{% endblocktrans %} {% trans 'My Text' %} 从 Django Docs Trans模板标签 The {% trans %} template tag translates either a constant string (enclosed in single o

概述

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

{% trans 'My Text' %}

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将允许你在你的输出中更复杂一些.

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

总结

以上是编程之家为你收集整理的Django i18n blocktrans vs trans全部内容,希望文章能够帮你解决Django i18n blocktrans vs trans所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶