[Solved]-Django i18n: recommended size and formatting for {% blocktrans %} blocks?


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

  • 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.

    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.

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):

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.

Leave a comment