This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
i18n
Tibo Stroo edited this page Apr 14, 2023
·
9 revisions
In our project, we decided enable internationalization support in our backend. Right now, we support Dutch and English.
Default Django error messages are automatically translated. If you write your own error messages, use _(<error-message>)
syntax. Where _()
is imported with from django.utils.translation import gettext_lazy as _
.
When you wrote custom error messages that you wish to translate, run django-admin makemessages --all --ignore=env
to add them to the *.po
files in backend/locale/
.
Now, take a look at the *.po
message files:
-
msgid
represents the translation string as it appears in the source code. -
msgstr
represents the language translation which you'll have to type yourself. It is empty by default, meaning there won't be a translation unless you explicitly give one.
After adding the translations, compile them by running django-admin compilemessages --ignore=env
, which will update the *.mo
files.