Django message files ¶
English messages: benefits/locale/en/LC_MESSAGES/django.po
The Cal-ITP Benefits application is fully internationalized and available in both English and Spanish.
It uses Django’s built-in support for translation using message files, which contain entries of
msgstr pairs. The
msgid is referenced in source code so that Django takes care of showing the
msgstr for the user’s language.
Updating message files ¶
Django has a utility command called
makemessages to help maintain message files. It ensures that
msgids in the message files are actually used somewhere in source code and also detects new
There is a helper script that runs this command with some arguments:
Developers should use this script to update message files in a consistent way.
Updating English ¶
Add English copy to templates directly first. Then, run the helper script,
bin/makemessages.sh, so Django can update the
django.po files for English and Spanish with the new copy.
Updating Spanish ¶
Find the English copy in the Spanish
django.po file as a
msgid, and add the corresponding Spanish translation as the
msgstr. Again, run the helper script for formatting and
bin/init.sh to confirm the translation is rendered properly.
Adding agency-specific copy ¶
When templates have different copy per agency, create a new template for that agency-specific copy to live in. See the example of the MST-specific agency index page file, named
index--mst.html. Include the agency-specific template file name in the migration object, as done here for MST, with
Fuzzy strings ¶
From Django docs:
makemessagessometimes generates translation entries marked as fuzzy, e.g. when translations are inferred from previously translated strings.
Usually, the inferred translation is not correct, so make sure to review the
msgstr and fix it if necessary. Then, remove the commented lines starting with
#, fuzzy (otherwise the entry will not be used).