Overriding a translation of a third-party Django module#
The Django Taggit app comes with
nice translations for German, but we have some technically inclined users, who
prefer the word „Tags“ over „Schlagwörter“. Still, we want to keep our de-de
locale for everything else. We choose only to override this one
translation.
Note that our Django app is called app
.
# The locale directory must be created. If not, you get
# "CommandError: Unable to find a locale path to store translations for file app/__init__.py"
mkdir -p app/locale/de/LC_MESSAGES/
# Usually, we would use "./manage.py makemessages" to collect our messages.
# Instead, we create a simple .po file
cat << EOF > app/locale/de/LC_MESSAGES/django.po
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "Tag"
msgstr "Tag"
msgid "Tags"
msgstr "Tags"
EOF
# Create the .mo files
./manage.py compilemessages -l de
We explicitly set the charset to UTF-8, so gettext uses the correct encoding
when creating .mo
files. To quote the Django
docs:
Due to the way the gettext tools work internally and because we want to allow non-ASCII source strings in Django’s core and your applications, you must use UTF-8 as the encoding for your PO files
Using apt-get to update specific versions
sleep infinity in docker-compose