我刚刚开始使用 Django 国际化并试图了解使用 {% blocktrans %}
的最佳实践.使用一个更好吗 {% blocktrans %}
对于每一段,还是我应该有一个大的 {% blocktrans %}
包含很多段落?
拥有一大把{% blocktrans %}
更快并且使我的模板看起来更干净,但我担心的是:
- 它使 HTML 标签(如
<p>...</p>
)成为翻译字符串的一部分 - 如果我改变我巨大区 block 的一部分中的一件事,
msgid
会改变,这似乎会影响其他段落。如果我有更小的 block ,变化会更加孤立(我想)。 - 如果我进行格式更改,例如在段落之间添加/删除换行符,则会更改
msgid
.
我也想知道格式化。在 {% blocktrans %}
内换行是否有任何并发症? ?或者有领先的空间?例如:
{% blocktrans %}
You have {{ num_messages }} messages.
Another sentence.
{% blocktrans %}
欢迎提出任何建议。
最佳答案
多个小的 {% blocktrans %}
block 有多种好处:
每个可翻译的字符串最终都会出现在翻译文件中,并且这些文件应该可以由说该语言的人翻译。他们不必处理 HTML 标签的正确性,但他们应该纯粹将一些句子翻译成该语言。次要标记可以,但不是整个页面的 HTML。
您也可以这样想:可翻译字符串中的标记越少,翻译人员(可能有也可能没有技术背景)出错的机会就越少。
如果一个巨大的翻译 block 发生变化,那么所有翻译都需要由每个翻译人员重新完成。如果您使用小的可翻译 block ,那么您可以重用大部分现有的已翻译段落/文本,您只需要为实际更改的部分获取更新的翻译。
所以回答你的问题:每个段落一个 blocktrans 标签是更好的选择。如果您最终更改了一段,那么只有该段需要由翻译人员再次检查。
关于空格和换行符:默认情况下,它们将出现在 PO 翻译文件中。在 Django 1.7 中,blocktrans 将有一个 trimmed
选项,可以删除空格和换行符 ( source ):
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.
关于python - Django 国际化 : recommended size and formatting for {% blocktrans %} blocks?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20150773/