django i18n support: fuzzy!
December 2014
Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
About
This site is an effort to share some of the base knowledge I have gathered through all this years working with Linux, FreeBSD, OpenBSD, Python or Zope, among others. So, take a look around and I hope you will find the contents useful.
Recent Entries
Recent Comments
Recent Trackbacks
Categories
OpenBSD (8 items)
BSD (0 items)
FreeBSD (19 items)
Linux (3 items)
Security (3 items)
Python (18 items)
Zope (13 items)
Daily (139 items)
e-shell (9 items)
Hacks (13 items)
PostgreSQL (3 items)
OSX (7 items)
Nintendo DS (0 items)
enlightenment (0 items)
Apache (3 items)
Nintendo Wii (1 items)
Django (23 items)
Music (12 items)
Plone (7 items)
Varnish (0 items)
Lugo (2 items)
Sendmail (0 items)
europython (7 items)
Cherokee (1 items)
self (1 items)
Nature (1 items)
Hiking (0 items)
uwsgi (0 items)
nginx (0 items)
bikes (0 items)
Archives

Syndicate this site (XML)

RSS/RDF 0.91

25 noviembre
2008

django i18n support: fuzzy!

well, it is not a matter of django, but of gettext anyway...

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:

../manage.py compilemessages

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.

Posted by wu at 23:06 | Comments (1) | Trackbacks (0)
<< A week since the WPD | Main | self() 2.9 released >>
Comments
Find non-translated strings.

I had to i18n a django app myself recently. I wrote a little tool to find all the non-translated strings in your django templates. Might be helpful to you and others.

http://www.technomancy.org/python/django-template-i18n-lint/

Posted by: Rory McCann at marzo 06,2011 19:58
Re: django i18n support: fuzzy!

you can use rosseta too https://github.com/mbi/django-rosetta

Posted by: bob at agosto 22,2013 11:05
Trackbacks
Please send trackback to:http://blog.e-shell.org/124/tbping
There are no trackbacks.
Post a comment