Reputation: 4529
My object has an attribute called status. Status can have two states: opened and closed. The value of this attribute should be translated. I've tried to do this in two ways:
<td> {% trans object.status %} </td>
and
<td>
{% blocktrans with object.status as status %} {{ status }} {% endblocktrans %}
</td>
but with no result. In django.po file I have an entry %(status)s. How will Django know how to translate the status?
Upvotes: 0
Views: 75
Reputation: 600026
If status can only have two states, you should use the choices
attribute in the model definition. The values for choices can then be marked for translation:
STATUS_CHOICES = (
('open', _('open')),
('closed', _('closed'))
)
class MyModel(models.Model):
status = models.CharField(max_length=10, choices=STATUS_CHOICES)
and in the template, use the get_status_display
method:
<td> {{ object.get_status_display }} </td>
Upvotes: 1
Reputation: 2457
check if you drop these 4 lines into the po:
msgid "opend"
msgstr "Your translated word"
msgid "closed"
msgstr "your trans word"
and run :
manage.py compiletranslation
because when you edit the .po file with existing .mo file, the change have no effect
Upvotes: 0