René M.
René M.

Reputation: 394

Django Template: Use translation in default_if_none

How can I use a translated string inside a template for default_if_none?
Usually you would use something like this: {% trans 'TRANSLATED STRING' %}

Example

{{ value|default_if_none:'TRANSLATED STRING' }}

Upvotes: 3

Views: 1347

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476719

You can store the translated string in a variable, like:

{% trans 'TRANSLATED STRING' as transl %}
{{ value|default_if_none:transl }}

It however might make sense to define a custom template filter [Django-doc] here.

Upvotes: 9

Related Questions