python lazy translation - 为翻译字符串添加换行符

时间:2015-01-17 01:32:44

标签: python django newline translation

如何为延迟翻译添加换行符?我搜索了django,SO&谷歌,但没有找到任何信息。

我的懒惰翻译使用下面的多行,但换行符/换行符会呈现在屏幕上。

messages.success(
    request,
    _("If the e-mail address has been registered, you'll receive an e-mail with instructions."
    "/n/n"
    "If you don't receive this e-mail, check your spam e-mail folder or contact us for assistance."))

我也试过< b r />和反斜杠n,但这些不会在django模板屏幕上呈现为新行。

1 个答案:

答案 0 :(得分:0)

您应该使用反斜杠\n作为换行符号。

请注意,\n符号是常规空格,在HTML页面上,它看起来像简单空格。如果您想显示多行消息,则应使用<br />代码并将消息设为“安全”:

from django.utils.safestring import mark_safe

messages.success(request,
        mark_safe("If the e-mail address has been registered ..."
                  "<br /><br />"
                  "If you don't receive this e-mail, check your spam ...."))