在一些 Django 模板中绘制以下 blocktrans
:
{% blocktrans %}
Some Text
{% endblocktrans %}
在模板中进行一些更改后,您可能希望缩进该 block :
<div>
{% blocktrans %}
Some Text
{% endblocktrans %}
</div>
这将更改翻译文件中的消息,并将它们标记为模糊。从技术上讲,这是相同的消息(只是缩进不同)。
“消除模糊化”这些消息的整个过程既乏味又容易出错。
到目前为止我尝试了什么:
- 尽可能多地使用
trans
——并不总是有效 - 保持
blocktrans
语句的初始缩进 - 难以维护 - 试图在文档和其他资源中找到更多信息
有没有办法让 blocktrans
中的缩进变得无关紧要?
最佳答案
根据文档here :
Another feature {% blocktrans %} supports is the trimmed option. This option will remove newline characters from the beginning and the end of the content of the {% blocktrans %} tag, replace any whitespace at the beginning and end of a line and merge all lines into one using a space character to separate them. This is quite useful for indenting the content of a {% blocktrans %} tag without having the indentation characters end up in the corresponding entry in the PO file, which makes the translation process easier.
例如
<div>
{% blocktrans trimmed %}
Some Text
{% endblocktrans %}
</div>
将在您的 PO 文件中生成条目 "Some Text"
。
关于python - 如何使 Django blocktrans 中的空格和缩进无关紧要?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40282464/