I am just getting started with Django internationalization and trying to understand the best practices for using {% blocktrans %}. Is it preferable to use one {% blocktrans %} for each paragraph, or should I have one big {% blocktrans %} that contains many paragraphs?

我刚刚开始介绍Django国际化,并试图了解使用{% blocktrans %}的最佳实践。对于每个段落使用一个{% blocktrans %},还是应该使用一个包含很多段落的大{% blocktrans %} ?

Having one big {% blocktrans %} is faster and makes my template look cleaner, but my concern is that:

有一个大的{% blocktrans %}更快,使我的模板看起来更干净,但是我担心的是:

  • it causes HTML tags (like <p>...</p>) to become part of the translation string
  • 它导致HTML标签(如

    )成为翻译字符串的一部分
  • If I change one thing in one part of my huge block, the msgid would change, which seems like it could affect the other paragraphs. If I have smaller blocks, the changes would be more isolated (I suppose).
  • 如果我在我的大块中改变了一件事,msgid就会改变,这似乎会影响到其他段落。如果我有更小的块,变化将会更加孤立(我想)。
  • If I make a formatting change like adding/removing a newline in between paragraphs, that would change the msgid.
  • 如果我进行格式更改,比如在段落之间添加/删除换行符,就会更改msgid。

I am also wondering about formatting. Are there any complications to having line breaks inside a {% blocktrans %}? Or having leading spaces? e.g.:

我还想知道格式化。在{% blocktrans %}中出现换行有什么并发症吗?或有领导空间?例如:

{% blocktrans %}
    You have {{ num_messages }} messages.
    Another sentence.
{% blocktrans %}

Any recommendations are welcome.

任何建议都是受欢迎的。

1 个解决方案

#1


9

Multiple small {% blocktrans %} blocks are beneficial for various reasons:

多个小的{% blocktrans %}块的好处是多方面的:

  • Each translatable string ends up in the translation files and these files should be translatable by people that speak the language. They should not have to deal with correctness of HTML tags but they should purely translate a few sentences to that language. Minor markup is fine but not the HTML of the entire page.

    每个可翻译的字符串都在翻译文件中结束,这些文件应该由说该语言的人翻译。他们不应该处理HTML标签的正确性,但是他们应该把一些句子翻译成那种语言。小标记很好,但不是整个页面的HTML。

    You can also think of it this way: the less markup in the translatable strings, the less chances for errors by translators (who may or may not have a technical background).

    您也可以这样想:可翻译字符串中的标记越少,译者出错的几率就越小(译者可能有技术背景,也可能没有技术背景)。

  • If a huge translation block changes then all translations need to be done again by each of the translators. If you use small translatable blocks then you can reuse most of the existing translated paragraphs / text and you only need to get updated translations for the parts that actually changed.
  • 如果一个巨大的翻译块发生了变化,那么所有的翻译都需要由每个翻译人员重新完成。如果您使用小的可翻译块,那么您可以重用现有的大多数已翻译段落/文本,并且您只需要获得实际更改的部分的最新翻译。

So to answer your question: a blocktrans tag per paragraph is a better choice. If you end up changing a paragraph then only that paragraph needs to be checked again by a translator.

因此,要回答你的问题:每个段落使用一个blocktrans标签是个更好的选择。如果你最终改变了一个段落,那么只有那个段落需要由翻译再次检查。

Regarding whitespace and newlines: by default these will end up in the PO translation files. In Django 1.7 the blocktrans will have a trimmed option which removes whitespace and newlines (source):

关于空格和换行:默认情况下,这些将在PO翻译文件中结束。在Django 1.7中,blocktrans有一个裁剪的选项,可以删除空格和换行(源):

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.

这个选项将从{% blocktrans %}标签的开头和结尾删除换行字符,替换行开头和结尾的任何空格,并使用空格字符将所有的行合并为一行。这对于缩进{% blocktrans %}标签的内容非常有用,而不会让缩进字符出现在PO文件的相应条目中,这使得转换过程更容易。

更多相关文章

  1. 计算所有字符,包括linux中的空格
  2. postgresql 数组 多了引号 空格处理
  3. sql2005指定字段插入空格。
  4. android textview空格占位符以及一些其他占位符汇总
  5. javascript去掉前后空格
  6. Java操作ini文件 ,解决properties文件中无法读取换行及空格
  7. Java将一个字符串中的多个连一起的空格变成单个空格

随机推荐

  1. Android SDK安装时出错“android Failed
  2. android源码学习之animation1
  3. EditText使用属性详解
  4. Android相对布局RelativeLayout各属性介
  5. .Net 转战 Android 4.4 日常笔记目录
  6. Android:控件样式触发
  7. Android中的六大布局
  8. Android中TextView中加图片,超链接,部分字
  9. Android中的drawable state的各种状态
  10. Android:布局(相对布局RelativeLayout)