In Django templates, you can use either {{ _("Hello World") }}
or {% trans "Hello World" %}
to mark strings to be translated. In docs, the “official” approach seems to be the {% trans %}
tag, but the _()
syntax is mentioned too once.
How these approaches differ (except syntax) and why should be one preferable rather than the other?
One difference is that you obviously can't use {% trans %}
with tags and filters. But does that mean that I can just use _()
everywhere, like {{ _("String") }}
? It works and looks much cleaner and more consistent than using {% trans "String" %}
with standalone strings and _()
with tags and filters.