[Answered ]-Django 1.6 Block Trans not working with variable

2👍

You must pass variables into blocktrans to use them inside. Without that django can’t translate this sentence, because when rendered it looks like this:

sentence = _('See your results here: <a href='%(results_url)s'>Results</a>" % {'results_url': results_url})

In other words, each time template is rendered, translation engine is getting string with results_url already populated.

You must make it equivalent to that code:

sentence = _('See your results here: <a href='%(results_url)s'>Results</a>") % {'results_url': results_url}

and to do that, simply pass your variable into blocktrans:

{% blocktrans with results_url=results_url %}See your results here: <a href='{{results_url}}'>Results</a>{% endblocktrans %}

Leave a comment