I am working on a project that is required to be internationalized. This means that every string must be wrapped in a call to gettext. It's very easy to miss one, so I've been using a tool called potpie to check that all strings go through gettext. potpie processes a .po file and 'fakes' each of the translations, by turning ascii characters into ƈřȧzẏ ƈħȧřȧƈŧḗřş ŀīķḗ ŧħīş. If you see any text that's not crazy, it means you've missed a call to gettext. This way we can check our .po for completeness before sending it to the translators.
To set up Django for using translation files, set the LOCALE_PATHS setting. This is where the .po and .mo files will be stored.
1 2 3
LOCALE_PATHS = [ os.path.join(BASE_DIR, 'locale'), ]
Faking the translations with potpie
Ask Django to generate the .po file for our language
./manage.py makemessages -l es
You should now have a file
locale/es/LC_MESSAGES/django.po containing all the
strings to be translated. It will have content that looks something like this:
1 2 3
#: templates/index.html:6 msgid "Home" msgstr ""
Now run install and run potpie to translate all the strings:
pip install https://github.com/fusionbox/potpie/archive/master.zip potpie locale/es/LC_MESSAGES/django.po
The messages in
django.po will now look like:
1 2 3
#: templates/index.html:6 msgid "Home" msgstr "[Ħǿḿḗ 靐ſϖı]"
Before Django can use the translations, they have to be compiled into the binary .mo format:
./manage.py compilemessages -l es
You will see a file called
Once you tell Django to use the es language:
LANGUAGE_CODE = 'es'
You should see all translated strings using the crazy fake language. If any string appears not crazy, you'll have to find it and add the call to gettext.
Once you've checked that all strings are translated, remove the faked .po file and generate a new one to send to the translators.
./manage.py makemessages -d djangojs -l es -e html,js potpie locale/es/LC_MESSAGES/djangojs.po