Internationalization: in Python code
Standard translation
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 ...
Get Mastering Django: Core now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.