SS_SS
SS_SS

Reputation: 63

Translating {{ model.name }} data dynamically in django template

Can anyone suggest shortest way to translate {{ model.name }} type of data in django template?

Upvotes: 0

Views: 202

Answers (1)

oruchkin
oruchkin

Reputation: 1295

Templates aren't supposed to do buisiness logic in django, in a good way you need to pass already translated data in your template.

Although if you actually in need to do it, you can use django filters:

Link to django documentation

Code may look like this:

new_filter.py

from django.template.defaulttags import register

@register.filter
def translator_filter(string_to_translate):
    translated_string = #do logic with translation here
    return translated_string

any_page.html

<p>{{ model.name|translator_filter }}</p>

Upvotes: 1

Related Questions