我有一个模板,我想在其中翻译一个字符串。
{% blocktrans with "www.mywebsite.com" as website_name %}footer-slogan{{ website_name }}{% endblocktrans %}
我已经生成了我的 po 文件,其中我已经将字符串翻译如下:
msgid "footer-slogan %(website_name)s"
msgstr "This is a test %(website_name)s"
在我生成的 html 文件中,我得到了这个未翻译的元素:
footer-slogan www.mywebsite.com
如果我从翻译后的字符串中删除变量,它会起作用:
msgid "footer-slogan %(website_name)s"
msgstr "This is a test"
我什至尝试从源翻译中删除变量,但将变量保留在翻译后的字符串中,问题是相同的:
template.html
{% blocktrans with "www.mywebsite.com" as website_name %}footer-slogan{% endblocktrans %}
django.po
msgid "footer-slogan"
msgstr "This is a test %(website_name)s"
我希望能够仅在翻译后的字符串上设置变量。
我在翻译的字符串上做错了什么?
最佳答案
你可以这样使用 :
{% blocktrans %}
{% with website_name="www.mywebsite.com" %}
{% trans 'footer-slogan{{ website_name }}' %}
{% endwith %}
{% endblocktrans %}
关于带有变量的 Django blocktrans,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46435085/