2

I want to translate a string in a Django template:

{% trans "Thank you. You may <a href=\"/logout\">log out</a> now." %}

So in English, the result would be:

Thank you, You may <log out> now.

But - as an example in German, I need:

Vielen Dank. Sie können sich nun <ausloggen>.

Where the text in <> is the hyperlink. Now the problem is that the order of words has changed, and I do not find a way how to do this. I did see in the documentation that this can be done in Python code, with "placeholders". But I need it in templates. Is there a way to do it? Also, to ease translation, I don't like HTML in my translation file. Any help is highly appreciated!

4

1 回答 1

0

正如@fsw 建议的那样,请参阅

你不应该硬编码“/logout”,你必须使用{% url "urlname" %}标签。看这里

也许是这样?(我没有测试它)

{% url "logout" as logoutvar %}

{% blocktrans with logoutvar as logoutvar %}

"Thank you. You may <a href="{{ logoutvar }}">log out</a> now."

{% endblocktrans %}
于 2013-05-11T04:14:11.470 回答