django translate variable content in template

thoslin picture thoslin · Jul 1, 2011 · Viewed 26.7k times · Source

I'm using {% trans %} template tag. Django docs say:

The {% trans %} template tag translates either a constant string (enclosed in single or double quotes) or variable content:

{% trans "This is the title." %} {% trans myvar %}

https://docs.djangoproject.com/en/1.3/topics/i18n/internationalization/#trans-template-tag

I found it impossible to do {% trans myvar %} because myvar simply doesn't show up in django.po file after running makemessages command.

Am I using it wrong? Could some help me with this?

Answer

Jeff Wilcox picture Jeff Wilcox · Jul 22, 2011

You can use the blocktrans template tag in this case:

{% blocktrans %} This is the title: {{ myvar }} {% endblocktrans %}