1
votes

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?

2
It works when I put the variable inside trans directly. {% trans house_post.house_type.name %}Michael Tedla

2 Answers

2
votes

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.

0
votes

The content of your blocktrans is most likely the content of {{house_type}}. Not sure where it comes from, but this is where you have to translate it. Don't forget to insert something like

from django.utils.translation import ugettext_lazy as _

to header of your py-files.