Search code examples
pythondjangodjango-i18n

Is there a good shortcut convention for ugettext_noop in python/django?


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 ?.


Solution

  • Based on the answer answer ugettext and ugettext_lazy functions not recognized by makemessages in Python Django the short answer is:

    • you could alias ugettext_noop to something else, but gettext won't recognize if alias is not one of the gettext keyword aliases.

    Summary: only one short alias (_) can be used, for other gettext functions you should not use aliases.