Specify a translation string by using the function ugettext()
. It's convention to import this as a shorter alias, _
, to save typing.
Python's standard library gettext
module installs _()
into the global namespace, as an alias for gettext()
. In Django, we have chosen not to follow this practice, for a couple of reasons:
For international character set (Unicode) support,
ugettext()
is more useful thangettext()
. Sometimes, you should be usingugettext_lazy()
as the default translation method for a particular file. Without_()
in the global namespace, the developer has to think about which is the most appropriate translation function.The underscore character (
_
) is used to represent the previous result in Python's interactive shell and doctest tests. Installing a global_()
function causes interference. Explicitly importingugettext()
as_()
avoids this problem.
In this example, the text "Welcome to my site."
is marked as a translation string...