Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django trans and url tags

Tags:

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.

like image 982
modocache Avatar asked Jun 30 '12 02:06

modocache


1 Answers

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 %} 
like image 70
Ned Batchelder Avatar answered Sep 19 '22 19:09

Ned Batchelder