Django 本地化:如果嵌入了链接,我们如何正确翻译字符串?
Django Localization: How do we properly translate a string if there are links embedded?
我们如何正确地向字符串添加翻译功能而不将它们分成更小的部分?我想让翻译人员能够更轻松地翻译字符串。
例如,请考虑以下内容:
<p>By clicking on "register", you agree to our <a href="{% url 'terms' %}">terms of service</a>, <a href="{% url 'privacy' %}">privacy policy</a> and <a href="{% url 'forum_guidelines' %}">forum guidelines</a></p>
如果我们使用反式标签 {% trans "" %}
,这将不得不分成 6 个独立的部分,这将很难本地化为其他语言:
1) {% trans "By clicking on "register", you agree to our" %}
2) {% trans "terms of service" %}
3) {% trans "," %}
4) {% trans "privacy policy" %}
5) {% trans "and" %}
6) {% trans "forum guidelines" %}
我已经阅读了 documentation,但我仍然不明白如何处理这个问题。我希望你们知道如何执行此操作或针对此类情况有适当的解决方案。
使用blocktrans
:
{% url 'terms' as terms_url %}
{% url 'privacy_url' as privacy_url %}
{% url 'forum_guidelines' as forum_guidelines_url %}
<p>
{% blocktrans trimmed %}
By clicking on "register", you agree to our
<a href="{{ terms_url }}">terms of service</a>,
<a href="{{ privacy_url }}">privacy policy</a> and
<a href="{{ forum_guidelines_url }}">forum guidelines</a>
{% endblocktrans %}
</p>
我们如何正确地向字符串添加翻译功能而不将它们分成更小的部分?我想让翻译人员能够更轻松地翻译字符串。
例如,请考虑以下内容:
<p>By clicking on "register", you agree to our <a href="{% url 'terms' %}">terms of service</a>, <a href="{% url 'privacy' %}">privacy policy</a> and <a href="{% url 'forum_guidelines' %}">forum guidelines</a></p>
如果我们使用反式标签 {% trans "" %}
,这将不得不分成 6 个独立的部分,这将很难本地化为其他语言:
1) {% trans "By clicking on "register", you agree to our" %}
2) {% trans "terms of service" %}
3) {% trans "," %}
4) {% trans "privacy policy" %}
5) {% trans "and" %}
6) {% trans "forum guidelines" %}
我已经阅读了 documentation,但我仍然不明白如何处理这个问题。我希望你们知道如何执行此操作或针对此类情况有适当的解决方案。
使用blocktrans
:
{% url 'terms' as terms_url %}
{% url 'privacy_url' as privacy_url %}
{% url 'forum_guidelines' as forum_guidelines_url %}
<p>
{% blocktrans trimmed %}
By clicking on "register", you agree to our
<a href="{{ terms_url }}">terms of service</a>,
<a href="{{ privacy_url }}">privacy policy</a> and
<a href="{{ forum_guidelines_url }}">forum guidelines</a>
{% endblocktrans %}
</p>