Question

This is the first time I used Django localization.

  1. I generated the .po files with makemessages and randomly select a few strings to fill in the translations, just to check if localization works.
  2. Then I generate the .mo file with compilemessages.
  3. I go to the web page and only see a string 'Username' translated, most other strings don't get the translated version displayed.

What is going on here?

EDIT: I found out why 'Username' is translated, it used the default translation in Django, but why Django didn't use my mo file is beyond me. I followed all the instructions in i18n doc.

  1. I set the LOCALE_PATHS variable in settings.py to the path for my localization files.
  2. I tried different LANGUAGE_CODE settings 'zh-cn', 'zh_CN'(both the setting variable and the directory name).
  3. I tried msgunfmt django.mo, the file is valid.

There are some lines close to the beginning of po file:

#, fuzzy
msgid ""
msgstr ""

I believe this is normal.

Was it helpful?

Solution

I finally got it working after hours of trial and error. I change my LOCALE_PATHS from:

LOCALE_PATHS = ("/path/to/locale/");

to:

LOCALE_PATHS = ("", "/path/to/locale/");

And it works right away. Maybe it is a bug with Django 1.5 (which I am using), or maybe I configured something wrong.

Anyway, hope this helps someone, and save you hours of time.

=========EDIT===========

As pointed out by @J.C.Leitão, you have to add comma to make the variable a tuple. It was a rookie mistake of mine. But I think Django could be more friendly to developers if a single string is recognized, too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top