'Django blocktrans with variable
I have a template, in which I want to translate a string.
{% blocktrans with "www.mywebsite.com" as website_name %}footer-slogan{{ website_name }}{% endblocktrans %}
I've generated my po file, in which I've translated the string as follow :
msgid "footer-slogan %(website_name)s"
msgstr "This is a test %(website_name)s"
On my generated html file, I get this untranslated element :
footer-slogan www.mywebsite.com
If I remove the variable from the translated string, it works :
msgid "footer-slogan %(website_name)s"
msgstr "This is a test"
I've even tried to remove the variable from the source translation but keeping the variable in the translated string, the issue is the same :
template.html
{% blocktrans with "www.mywebsite.com" as website_name %}footer-slogan{% endblocktrans %}
django.po
msgid "footer-slogan"
msgstr "This is a test %(website_name)s"
I'd prefer to be able to set the variable only on the translated string.
What I'm doing wrong on the translated string?
Solution 1:[1]
You can use it this way:
{% blocktrans %}
{% with website_name="www.mywebsite.com" %}
{% trans 'footer-slogan{{ website_name }}' %}
{% endwith %}
{% endblocktrans %}
Solution 2:[2]
Little late to answer but for other people that come seeking
`{% blocktrans with site_name="xyz" %}{{ site_name }} - Your account
has been successfully created and activated!{% endblocktrans %}`
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Sachin |
