Search code examples
djangodjango-i18n

Django: blocktrans entry is not being translated


I have this block in my HTML

...
<a class="header" href="{% url 'listing' house_post.id %}">
  {% blocktrans with house_type=house_post.house_type.name trimmed %}
    {{house_type}}
  {% endblocktrans %}
</a>
...

One value of house_type is "Condominium". I've added the following entry in my .po file.

msgid "Condominium"
msgstr "ኮንዶሚኒየም"

I've run compilemessages on the po file, and the rest of the translations work when I switch languages. And I've made sure the value of house_type is set to "Condominium". But for some reason it's not being translated.

In addition when I run makemessages the tool comments out additions I've made in the .po files. I'm uncommenting them before running compilemessages. I don't know why it's doing that though it might be a clue.

It is possible to add translation texts to .po files. Isn't it?


Solution

  • It's not translated because {{house_type}} will have the value of house_post.house_type.name.

    The blocktrans actually does nothing in your code. You would need it if you want to add a translatable text to the sentence. Ex:

      {% blocktrans with house_type=house_post.house_type.name trimmed %}
        {{house_type}} Translate this part
      {% endblocktrans %}
    

    If you want to have a translated variable, you have to pass the translations to house_post.house_type.name.