django i18n support: fuzzy!
It took me some time until I discovered this, so I think it would be nice to post about it.
In a recent project, I needed to add i18n support to a django app. This was the first project that needed such support since the first time i used django some time ago, so I took a look at the official docs, I read some posts in some blogs over the internet and I followed three easy steps:
1- Inside my app dir, I used the manage.py tool to generate the needed .po files for my language (.es):
../manage.py makemessages -l es
2- Then I opened up emacs and I used the po mode to edit the .po file (locale/es/LC_MESSAGES/django.po inside my app dir). It is pretty easy to edit a .po file, you could use any text editor to add the translated strings in place, but the po mode has some interesting shortcuts to get it done quickly.
3- Finally I generated the .mo file that contains the pre-compiled translation information, again, using manage.py inside my app dir:
Then I restarted my django server (I would have to restart apache if we have the app in a production environment) and I tested the app on a web browser.
Nice! It seemed to work, everything was in .es now... but... wait... there were still some untranslated texts.
I went back to emacs and I revised the whole .po file, everythin seemed to be ok, I regenerated the .mo file and restarted the server again... and those strings were still untranslated.
Then something catched my eye in the .po file, the word fuzzy:
#: models.py:75 #, fuzzy msgid "Public states" msgstr "Publicados"
Seems like the fuzzy mark prevents the strings marked as fuzzy to be translated, as that means it is marked for translator revision (more info: http://www.gnu.org/software/automake/manual/gettext/Fuzzy-Entries.html#Fuzzy-Entries ).
To solve this problem, I just removed the fuzzy mark, I regenerated the .mo file and I restarted the server once more. And then everything was correctly translated.