[英]Django template: Translate include with variable
我有一个模板,您可以在其中传递文本变量。 我想将此模板包含在另一个模板中,但带有翻译文本,因为它是可变的。 你怎么能做到这一点?
我想要这样的东西:
{% include "a_dir/stuff.html" with text={% trans "Load more promotions" %} %}
我很难编写自己的模板标签来执行ugettext
但是在创建.po
文件时,文本变量不会被自动获取。
我不想在view
做这项工作,因为我们所有的翻译都是在模板中进行的。
您可以使用as
语法将已翻译的字符串放入变量中。 例如:
{% trans "Load more promotions" as promotions %}
{% include "a_dir/stuff.html" with text=promotions %}
有关更多详细信息,请参阅文档 。
更短的方法是
{% include 'a_dir/stuff.html' with text=_("Load more promotions") %}
这也适用于变量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.