15.2. Locale i18n

15.2.1. Rationale

  • i18n = internationalization

15.2.2. Examples

pl_PL.UTF-8:

hello = 'witaj'

en_US.UTF-8:

hello = 'hello'

en_GB.UTF-8:

hello = 'good morning'

15.2.3. Gettext

  • .po files

  • .mo files

  • Using gettext in code

  • Generating translation files

  • Compiling translation files

  • Updating translation files

  • Transifex (tx push and tx pull)

15.2.4. Django

  • django-admin makemessages -l en

  • django-admin compilemessages

  • {% blocktranslate %} and {% endblocktranslate %}

  • {% translate %}

  • 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 myproject
$ 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/myproject/locale/en/LC_MESSAGES
processing file django.po in /tmp/myproject/locale/pl/LC_MESSAGES

15.2.5. Poedit

../_images/locale-i18n-poedit1.png
../_images/locale-i18n-poedit2.png
../_images/locale-i18n-poedit3.png