django translation tips: makemessages and gettext pitfalls & blocktrans best practises

Below I share some best practises and experiences I had with Django’s gettext implementations.

Fuzzy translations

Fuzzy translations are one of the bigger challenge when using gettext for translation. The following is a best practise in coping with them:

“Fuzzy” messages for not make it into the translation. They are not considered to be translated correctly, but they are not deleted, since they are likely to be “almost correct” and just need a small update.

Part of normal translator operations is to search out any “fuzzy” messages and verify that they are either still correct (just delete the fuzzy comment, but do not delete the python-format bit) or update them and then remove the “fuzzy”.

This isn’t anything special to Django, by the way. It’s the way
gettext-backed i18n support operates.

Malcolm Tredinnick at!msg/django-users/SjqjUhZwJzU/DaHmdwZeZLkJ

The Django blocktranstag

Best practice: Always use the `trimmed` option. This results in a nicely formatted block of text in the po file which makes it simpler for translators to handle it. If the translation key is not trimmed, arbitrary line breaks make it difficult to translate properly.

{% blocktrans trimmed with business_name=business_name context "password reset email" %}
You're receiving this email because you requested a password reset for your user account at {{ business_name }}.

Another line, which will be trimmed into one single block of text inside the po file so that this can be properly formatted.
{% endblocktrans %}

Translation Process

  1. After changes in the code and templates the developer updates the po files with makemessages command and review the updates in the re-generated po files and then commits them to the source, best via a Merge Request. Its not a good idea to add new translation entries from templates or code to a po file manually. django makemessages command takes care of this and makes sure everything is updated correctly. (edited)
  2. compilemessages is then normally run during deployment in the deploy script. It generates the compiled .mo files that are needed by Django to display the translations.