11.4. Manage Translation
python manage.py makemessages -l en
python manage.py compilemessages
gettext
from django.utils.translation import gettext_lazy as _
_('string')
{% blocktranslate %}
and{% endblocktranslate %}
{% translate "string" %}
LANGUAGE_CODE = 'en-us'
USE_I18N = True
django.middleware.locale.LocaleMiddleware
.po
and.mo
fileslocale
directory
11.4.1. Timezone
django.utils.timezone
from 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'
11.4.2. Gettext
.po
files.mo
filesUsing
gettext
in codeGenerating translation files
Compiling translation files
Updating translation files
Transifex (
tx push
andtx pull
)
11.4.3. i18n - internationalization
from django.utils.translation import gettext_lazy as _
{% blocktranslate %}
and{% endblocktranslate %}
{% translate %}
python manage.py makemessages -l en
python manage.py compilemessages
transifex-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