Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make spaces and indentation insignificant in Django blocktrans?

Image the following blocktrans in some Django template:

{% blocktrans %}
    Some Text
{% endblocktrans %}

After some changes in the templates, you might like to indent the block:

<div>
    {% blocktrans %}
        Some Text
    {% endblocktrans %}
</div>

This is going to change your message in the translation files, and mark them as fuzzy. While technically, it is the same message (only the indentation is different).

The whole process of "unfuzzyfying" those messages is tedious and error-prone.

What I tried so far:

  • Using trans as much as possible - doesn't always work
  • Keeping the initial indentation of blocktrans statements - hard to maintain
  • Tried to find more information in documentation and other resources

Is there a way to make the indentation in blocktrans insignificant?

like image 621
Jordan Jambazov Avatar asked Oct 27 '16 10:10

Jordan Jambazov


1 Answers

According to the documentation 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.

so for example

<div>
    {% blocktrans trimmed %}
        Some Text
    {% endblocktrans %}
</div>

will result in the entry "Some Text" in your PO file.

like image 175
rafalmp Avatar answered Oct 26 '22 04:10

rafalmp