13.5 Translation

In many of the contributed apps, you will discover the existence of the locale/ directory. In the code of these apps, you will furthermore run into code that looks like _('a string value'). Both the directory and the -() function are part of Django’s translation framework.

The -() is actually a shortcut for the ugettext() or ugettext_lazy() functions. You may discover this by looking at the imports of the files using the -() convention, shown in Example 13.10.

Example 13.10: Python Code

from django.utils.translation import ugettext_lazy as _

Both ugettext() and ugettext_lazy() mark a string for translation. The translation framework will take all these strings and allow a person to translate them. ...

Get Django Unleashed 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.