8.2. Locale i18n

8.2.1. Rationale

  • i18n = internationalization

8.2.2. Examples

Listing 8.60. pl_PL.UTF-8
hello = 'witaj'
Listing 8.61. en_US.UTF-8
hello = 'hello'
Listing 8.62. en_GB.UTF-8
hello = 'good morning'

8.2.3. Gettext

  • .po files

  • .mo files

  • Using gettext in code

  • Generating translation files

  • Compiling translation files

  • Updateting translation files

  • Transifex (tx push and tx pull)

8.2.4. Django

  • django-admin makemessages -l en

  • django-admin compilemessages

  • {% blocktranslate %} i {% endblocktranslate %}

  • {% translate %} templatetag

  • from django.utils.translation import gettext_lazy as _

  • transifex-client

  • gettext

  • poedit

# Internationalization
# https://docs.djangoproject.com/en/dev/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
$ cd djangoproject
$ mkdir locale

$ django-admin makemessages -l en
processing locale en

$ django-admin makemessages -l pl
processing locale pl

$ django-admin compilemessages
processing file django.po in /tmp/djangoproject/locale/en/LC_MESSAGES
processing file django.po in /tmp/djangoproject/locale/pl/LC_MESSAGES