开发者

Translating text blocks with Django .. what to do with the HTML?

开发者 https://www.devze.com 2023-01-10 05:14 出处:网络
The title might not be clear, but I don\'t know how else to put it.. In the Django documentation it\'s pretty clear how to mark a text block for translation .. Take this example:

The title might not be clear, but I don't know how else to put it..

In the Django documentation it's pretty clear how to mark a text block for translation .. Take this example:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Donec quam sem, sodales in fringilla nec, lacinia a lorem. 
Vivamus vel mole开发者_如何学Cstie ante. 

So far so good. You just either use the trans or blocktrans tag.

But now consider this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Donec quam sem, sodales in fringilla nec, lacinia a lorem. 
<a href="{% url some-view %}">Vivamus vel</a> molestie ante.

How should I deal with this ? Do I just wrap it in a block trans ?

Edit:

I think I've found out how it should be done ..

{% url some-view as some_view_url %}
{% blocktrans %}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Donec quam sem, sodales in fringilla nec, lacinia a lorem. 
<a href="{{ some_view_url }}">Vivamus vel</a> molestie ante.
{% endblocktrans %}


I would definitely use blocktrans. Sometimes its not possible to split i18n html text into different fragments. Blocktrans has some powerfull features:

{% url path.to.view arg arg2 as the_url %}

{% blocktrans with object.title as title and author|title as author_t %}

  {{author}}: Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
  Donec quam sem, sodales in fringilla nec, lacinia a lorem. 
  <a href="{{the_url}}">{{title}}</a> molestie ante.

{% endblocktrans %}

Have a look at:

  • url template tag
  • blocktrans template-tag
0

精彩评论

暂无评论...
验证码 换一张
取 消