0

When doing i18n support for django apps it sometimes comes up to have to use ugettext and ugettext_noop in the same file. It's a common convention to import ugettext as _ which is a nice convention in code. I'm wondering if there is such a convention for ugettext_noop? Maybe __?

I'm envisioning something like this:

from django.utils.translation import ugettext as _, ugettext_noop as ?

MY_CONSTANT = ?('translate me later')

def my_function():
    return _('translate me now')

Fill in the ?.

4

1 回答 1

4

根据Python Django 中 makemessages 无法识别的答案答案 ugettext 和 ugettext_lazy 函数,简短的答案是:

  • 您可以将 ugettext_noop 别名为其他名称,但如果 alias 不是 gettext 关键字别名之一,gettext将无法识别。

总结:只能使用一个短别名 ( _),对于其他 gettext 函数,您不应该使用别名。

于 2013-05-20T21:32:56.767 回答