Django has full support for internationalization of text in code and templates, and format localization of dates and numbers. Here’s how it works.
Essentially, Django does two things:
The complete process can be seen as divided in three stages. It is also possible to identify an identical number of roles with very well defined responsibilities associated with each of these tasks (although it’s perfectly normal if you find yourself performing more than one of these roles):
For more general information about the topic, see the GNU gettext documentation and the Wikipedia article.
First lets define some terms that will help us to handle a common language:
Django’s translation machinery uses the standard gettext module that comes with Python. If you know gettext, you might note these specialties in the way Django does translation:
Django uses technical message IDs to translate date formats and time formats. Technical message IDs are translation strings and can be easily recognized; they’re all upper case. You don’t translate the message ID as with other translation strings, you provide the correct local variant on the provided English value. The format is identical to the format strings used by the now template tag.
For example, with DATETIME_FORMAT (or DATE_FORMAT or TIME_FORMAT), this would be the format string that you want to use in your language. A Django contributor localizing it to Spanish probably would provide a "j N Y P" “translation” for it in the relevant django.po file:
msgid "DATETIME_FORMAT"
msgstr "j N Y P"
Jul 05, 2010