Django trans and url tags

django, internationalization

Solution

Use `{% blocktrans %}`. The Django translation docs include this example:

{% url path.to.view arg arg2 as the_url %}
{% blocktrans %}
This is a URL: {{ the_url }}
{% endblocktrans %}

Problem

I want to translate a paragraph containing a URL in a Django 1.3 application. ``` <p> First <a href="{% url edit-profile username=user.username %}">edit your profile</a>, please. </p> ``` Depending on the language, the text surrounded by `<a>` tags will surely change. How can I allow translators to decide on the link placement? Wrapping the entire thing in a `{% trans %}` causes an error: ``` <p>{% trans "First <a href='{% url edit-profile username=user.username %}'>edit your profile</a>, please." %}</p> ``` The error thrown is `TemplateSyntaxError: Searching for value. Unexpected end of string in column 64: trans "First <a href='{% url edit-profile username=user.username`. How should I go about doing this? Do I have to determine the URL in the view, then pass that URL as a string to the template? That seems like a really convoluted solution for what I would think is a very common problem.

Original source