Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make strings inside trans tag uppercased

In my template, sometimes I want to make the translated string passed through upper filter. For example, I want to display "Related Links" as "RELATED LINKS". However when I tried, e.g:

{% trans "Related links"|upper %}

TemplateSyntaxError would be thrown. Any suggestions?

like image 610
pram Avatar asked Nov 14 '12 20:11

pram


2 Answers

Just use:

{% trans "Related links" as rel %}{{ rel|upper }}

This saves the translation temporarily in a variable which then can be used to apply filters on it.

Source: https://docs.djangoproject.com/en/dev/topics/i18n/translation/#trans-template-tag

like image 57
j0ker Avatar answered Nov 16 '22 19:11

j0ker


Since Django 1.10, you can avoid aliases and just use:

{% trans "Related links"|upper %}
like image 2
Dos Avatar answered Nov 16 '22 17:11

Dos