【问题标题】:Django Localization: How do we properly translate a string if there are links embedded?Django Localization:如果嵌入了链接,我们如何正确翻译字符串?
【发布时间】:2020-10-22 23:30:00
【问题描述】:

我们如何正确地为字符串添加翻译功能而不将它们分成更小的部分?我想让翻译人员能够更轻松地翻译字符串。

例如,请考虑以下几点:

<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,但我仍然不明白如何解决这个问题。我希望你们知道如何做到这一点,或者对这种情况有适当的解决方案。

【问题讨论】:

    标签: django django-templates localization internationalization


    【解决方案1】:

    使用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>
    

    【讨论】:

    • 对不起,“不显示网址”是什么意思?该示例可以很好地与翻译人员使用的所有主要工具配合使用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-24
    • 1970-01-01
    • 2016-01-17
    • 2016-06-18
    • 2018-11-18
    • 1970-01-01
    • 2016-11-21
    相关资源
    最近更新 更多