django在模板中翻译变量内容 [英] django translate variable content in template
问题描述
我正在使用{%trans%}模板标签。 Django文档说:
I'm using {% trans %} template tag. Django docs say:
{%trans%}模板标记翻译一个常量字符串(用单引号或双引号括起来)或变量内容:
The {% trans %} template tag translates either a constant string (enclosed in single or double quotes) or variable content:
{%trans这是标题。 %}
{%trans myvar%}
{% trans "This is the title." %} {% trans myvar %}
https://docs.djangoproject.com/en/1.3/topics/i18n/国际化/#trans-template-tag
我发现无法做{%trans myvar%},因为myvar根本不显示在django.po文件运行makemessages命令后。
I found it impossible to do {% trans myvar %} because myvar simply doesn't show up in django.po file after running makemessages command.
我使用错了吗?可以帮助我吗?
Am I using it wrong? Could some help me with this?
推荐答案
您可以使用 blocktrans
在这种情况下的模板标签: / p>
You can use the blocktrans
template tag in this case:
{% blocktrans %} This is the title: {{ myvar }} {% endblocktrans %}
这篇关于django在模板中翻译变量内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!