简体   繁体   English

使用Django翻译文本块..如何处理HTML?

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

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: 在Django文档中,很清楚如何标记要翻译的文本块。举个例子:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Donec quam sem, sodales in fringilla nec, lacinia a lorem. 
Vivamus vel molestie ante. 

So far so good. 到现在为止还挺好。 You just either use the trans or blocktrans tag. 您只需要使用trans或blocktrans标记。

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 ? 我只是将它包裹在块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. 我肯定会使用blocktrans。 Sometimes its not possible to split i18n html text into different fragments. 有时候不可能将i18n html文本分成不同的片段。 Blocktrans has some powerfull features: Blocktrans有一些强大的功能:

{% 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: 看一下:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM