Internationalization - top level locale .mo files generated but not recognised in Django 1.5

968 views
Skip to first unread message

katstevens

unread,
Aug 6, 2013, 12:02:03 PM8/6/13
to django...@googlegroups.com
I am currently upgrading a project from Django 1.3 to 1.5 and having trouble getting Django to recognise my compiled .mo translations.

My project is structured as follows:

/toplevelfolder
    /myproject
        /app1
        /app2
        /app3
        /templates
            /app1templates
            /app2templates
            /app3templates
    /locale

And I have the following in my settings.py file:

LOCALE_PATHS = (
'/path/to/toplevelfolder/locale'
)

When I run the 'makemessages -l de' command in /toplevelfolder, the django.po file is created correctly in the toplevelfolder/locale/de/LC_MESSAGES folder with no errors. I add a test string (in this case for a form label) such as: 

#: .\myproject\app1\usersignupform.py:56
msgid "I accept the terms and conditions."
msgstr "I accept the German terms and conditions"

Running 'compilemessages' creates the django.mo file with no errors, so I restart my test server as usual. 

However the test translation string above does not show on the form label - only the Django in-house translations (e.g. basic form validation strings) are being displayed (so the language is definitely set to German). 

Interestingly I tried using lower level /locale folders within the app1, app2 folders and the strings were successfully compiled and displayed. But obviously this only covers the strings in my app code - when I try doing the same within my separate template folder, the files are generated ok but just don't display on the page after compiling, like at the top level. In any case, there are a dozen apps in my project and many shared strings - it would obviously be ideal to get makemessages working at the top level and collate them into one django.po file for our translator.

I am using {% load i18n %} in all the relevant templates and the top level method above worked perfectly well with the same project in Django 1.3, so it is unlikely to be a typo in my template or app code. Should it matter where the template directory is, as long as it's within the scope of where I'm calling django-admin.py (i.e. /toplevelfolder)?

For completeness: I have installed gettext-tools-0.17 for Windows and added the /bin files to my PATH variable (i.e. running xgettext --version from the command line is fine).

I also tried refreshing my Middleware cache by commenting out 'django.middleware.locale.LocaleMiddleware' in my settings and then putting it back in again (as I saw suggested elsewhere), with no luck.

I'd be grateful for any suggestions! Please ask if anything is unclear.



katstevens

unread,
Aug 7, 2013, 4:26:38 AM8/7/13
to django...@googlegroups.com
To follow up on this - when I moved my locale files to a completely new location and used a different path in my LOCALE_PATHS settings, the translations worked fine. I think it may have been a folder permissions issue.

Mario J. Barchéin

unread,
Nov 12, 2013, 12:02:33 PM11/12/13
to django...@googlegroups.com
I had the same problem. LOCALE_PATHS must be a tuple:

Wrong:

LOCALE_PATHS = (
'/path/to/toplevelfolder/locale'
)

Correct (look at the comma at he the end of the path):

LOCALE_PATHS = (
'/path/to/toplevelfolder/locale',
)

Just spent 1 hour tying to figure out why it wasn't working.

Bye.
Reply all
Reply to author
Forward
0 new messages