Home > OS >  Django i18n multi-line translate
Django i18n multi-line translate

Time:03-29

How to translate the snippet below using django's internalization?

utils.py

template = _("Below is the result of your WWE Account verification.\n"
             "Thank you!")

django.po

# try
msgid "Below is the result of your WWE Account verification.\nThank you!"
msgstr "A continuación se muestra el resultado de la verificación de su cuenta WWE.\n ¡Gracias!"

But when I do the code snippet below...

$ python manage.py shell
>>> from django.utils.translation import activate, ugettext_lazy as _
>>> activate('zh-cn')
>>> template = _("Below is the result of your WWE Account verification.\n"
                 "Thank you!")
>>> template
以下是您的 WWE 帐户验证结果。\n谢谢

The above outout of template is wrong. I expected a new line like below:

以下是您的 WWE 帐户验证结果。
谢谢!

or

Below is the result of your WWE Account verification.
Thank you!

UPDATE 03-29-2022

  • Turns out that I am already correct. I tried print(template) and it is working as intended

CodePudding user response:

Have you tried to print it? Sometimes the REPL doesn't display a string as it would be printed, instead it shows it's raw content.

  • Related