Wednesday, August 20, 2014

Django: HowTo Apply Template-Filters To A Translated String

Recently I faced the problem, to apply a django template filter to a translated string:

<p>{% trans 'yes' %}</p>

In this case I would like the displayed translation in upper letters. In order not to generate a second translation, I would like to apply the build-in upper filter.

Solution

There's a build-in filter tag, which is very useful in this case:

<p>{% filter upper %}{% trans 'yes' %}{% endfilter %}</p>