Django i18n + 模板 include 标签

3
我需要渲染已翻译的推荐信,并且我使用包含块来添加推荐信代码,如下所示:
{% include "includes/blog/testimonial.html" with text="This is the best product I've ever used!" name="Tim Z" description="Store Manager" %}

我该如何使用blocktrans标签与include标签一起使用,以呈现已翻译的包含标签呢?
谢谢!
1个回答

8

如果我理解正确,您想将提供的文本翻译为“include”标签。 如果是这样,请预先翻译它并将结果保存到变量中:

{% trans "This is the best product I've ever used!" as text %}
{% trans "Store Manager" as description %}
{% include "includes/blog/testimonial.html" with text=text name="Tim Z" description=description %}

好的,我现在会尝试一下并告诉你。 - tzenderman
2
顺便提一下,包含的模板可以访问主上下文,所以在这种情况下,您只需编写 {% include "includes/blog/testimonial.html" with name="Tim Z" %},但是我想说明一个更大的问题。 - Ludwik Trammer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接