How to translate a variable with django?

1.6k views Asked by At

I have a variable my_variable which can be onlye one of two values ("Swedish" or "English"). Then why can't I do this {% trans "{{ my_variable|capfirst }}" %} ? How should it be done? I want to translate the variable but it doesn't come out right.

2

There are 2 answers

0
noisy On BEST ANSWER
{%blocktrans%} This is the title: {{myvar}} {%endblocktrans%}

or

<title>{% trans myvar %}</title>

django translate variable content in template

0
AudioBubble On

Just use the {% blocktrans %} tag to include variable for translation.For more detailesFollow this link with search blocktrans keyword.

{% blocktrans with amount=article.price %}
That will cost $ {{ amount }}.
{% endblocktrans %}

It may help you.Thank you.