Django locale message bundles
In the previous section Django language selection workflow you used the Django admin to experiment how to visualize Django pages in different languages. The source of these different language translations is in Django's built-in locale message bundles.
Locale message bundles are text files that consist of translation message ids and the corresponding translated text for the id in a given language. Although it's technically possible to manually build locale message bundles, locale message bundles are either built-in to Django or automatically created, the latter by searching a Django project's source code for translation message ids.
In listing 13-4, you can see the LANGUAGES
variable in settings.py
file uses four different translation message ids – 'Spanish'
, 'English'
, 'French'
and 'German'
– defined through the django.utils.translation.gettext_lazy
method that uses the _
syntax convention.
As it turns out, these four translation message ids are already provided as part of the Django distribution itself (i.e. you don't need to create translations for them). The Django distribution includes locale message bundles for over ten built-in packages (e.g. configuration [conf
package], the Django admin [contrib.admin
package], user authentication [contrib.auth
package]) and with support for close to one-hundred languages, this means there are over one-thousand locale message bundles in the Django distribution.
This content for Django 3.2 LTS is only available in the paid version.