Django blocktrans with variable

Viewed 2099

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?

2 Answers

You can use it this way:

{% blocktrans %} 
    {% with website_name="www.mywebsite.com" %}
        {% trans 'footer-slogan{{ website_name }}' %}
    {% endwith %}   
{% endblocktrans %}

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 %}`
Related