0

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.

NeoWang
  • 17,361
  • 24
  • 78
  • 126
  • 1. Is there any "fuzzy" in the translations? See e.g. [this question](http://stackoverflow.com/q/1377372/931303); 2. did you restarted the server? – Jorge Leitao Mar 23 '14 at 22:44
  • 1. There are default fuzzy lines. See above. 2.I have restarted the server, to no avail. – NeoWang Mar 24 '14 at 03:27

1 Answers1

1

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.

NeoWang
  • 17,361
  • 24
  • 78
  • 126
  • 2
    It is not a bug: the former makes LOCALE_PATHS a string, the latter makes it a tuple. As the name of the variable suggests, it must be a tuple. You can use `LOCALE_PATHS = ("/path/to/locale/",)` so python interprets it as a tuple. – Jorge Leitao Mar 24 '14 at 06:22
  • 1
    You can (and should) accept your answer. It is the correct one :) – Jorge Leitao Mar 24 '14 at 06:23
  • @J.C.Leitão Ha, that's interesting. Thanks! – NeoWang Mar 24 '14 at 11:45