如何在运行`django-admin makemessages时忽略Django的.po文件中已翻译的字符串

时间:2017-06-20 12:15:50

标签: django internationalization

我的Django应用程序使用了一些已经在Django中翻译的字符串。在密码重置过程的自定义模板中,我希望在完成重置过程后使用一些原始文本,例如create a TCP tunnel

自定义模板包含<p>{% trans "Your password has been set. You may go ahead and log in now." %}</p>直接取自this one prompting user to log in

运行django-admin makemessages后我的.po文件包含:

#: core/templates/auth/password-reset-complete.html:10
msgid "Your password has been set.  You may go ahead and log in now."
msgstr ""

翻译工作正常,呈现页面已包含正确的翻译字符串。 是否可以自动从.po文件中省略此空翻译?只需删除它只会再次运行makemessages。它已被翻译,在我的.po文件中复制它似乎是不必要的。

1 个答案:

答案 0 :(得分:1)

您可以尝试将字符串放入变量中,然后再将其提交给trans,以便makemessages不会注意到它。像

这样的东西
{% with mystr="Your password has been set.  You may go ahead and log in now." %}
{% trans mystr %}
{% endwith %}

或者,您可以创建自己的自定义模板代码,只需在其参数上调用gettext(来自django.utils.translation),然后使用该代码而不是trans

相关问题