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.
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 %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With