12.4. Manage Translation
python manage.py makemessages -l enpython manage.py compilemessagesgettextfrom django.utils.translation import gettext_lazy as __('string'){% blocktranslate %}and{% endblocktranslate %}{% translate "string" %}LANGUAGE_CODE = 'en-us'USE_I18N = Truedjango.middleware.locale.LocaleMiddleware.poand.mofileslocaledirectory
12.4.1. Timezone
django.utils.timezonefrom django.conf.locale.en import formats as en_formats
>>> en_formats.DATETIME_FORMAT = 'Y-m-d H:i'
>>> en_formats.DATE_FORMAT = 'Y-m-d'
>>> en_formats.TIME_FORMAT = 'H:i'
>>>
>>> USE_TZ = True
>>> TIME_ZONE = 'UTC'
12.4.2. Gettext
.pofiles.mofilesUsing
gettextin codeGenerating translation files
Compiling translation files
Updating translation files
Transifex (
tx pushandtx pull)
12.4.3. i18n - internationalization
from django.utils.translation import gettext_lazy as _{% blocktranslate %}and{% endblocktranslate %}{% translate %}python manage.py makemessages -l enpython manage.py compilemessagestransifex-client
gettext
poedit
ChatGPT
Github Copilot
Append to myproject/settings.py:
>>> LANGUAGE_CODE = 'en-us'
>>> USE_I18N = True
>>> USE_L10N = True
$ cd myproject/shop
$ mkdir -p locale
$ python manage.py makemessages -l en
processing locale en
$ python manage.py makemessages -l pl
processing locale pl
$ python manage.py compilemessages
processing file django.po in /src/myproject/shop/locale/en/LC_MESSAGES
processing file django.po in /src/myproject/shop/locale/pl/LC_MESSAGES