Nasty surprise of Django and gettext

18 January 2009   3 comments   Django

Mind That Age!

This blog post is 9 years old! Most likely, its content is outdated. Especially if it's technical.

I've done a site that is initially only going to be in Swedish. So I set the LANGUAGE_CODE like this:

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'sv-SE'

I then go ahead and mark my templates and code and run django-admin.py makemessages -l sv-SE. Then I fire up Poedit to translate the .po file and then compile to make the .mo file, so now I had a file called <my project>/locale/sv-SE/LC_MESSAGES/django.mo but it just wouldn't work!! I tried debugging django.utils.translation with little success. Eventually through trial-and-error I found that if I change it to "sv" instead of "sv-SE" it works.

Is this a problem with gettext or a problem somewhere in Django? It might cause equally much headache for other developers so I wouldn't mind that we get to the bottom of this.

Comments

Ramiro Morales

Try using

LANGUAGE_CODE='sv-se'

and

django-admin.py makemessages -l sv_SE

This is described, granted it's not totally clear, in the Django I18N documentation at:

http://docs.djangoproject.com/en/dev/topics/i18n/#id2

http://docs.djangoproject.com/en/dev/topics/i18n/#message-files

respectively.

HTH

oggy

sv-SE will work just fine but you need to name your directory sv_SE instead of sv-SE

Tome

I spent several hours with trial and error to come up with the same conclusion, finally I used LANGUAGE_CODE='sv' and sv_SE for makemessages.

The documentation is indeed very vague when it comes to this :)

Your email will never ever be published


Related posts

Previous:
Formatting numeric amounts in Javascript 16 January 2009
Next:
Rock stars and their parents 19 January 2009
Related by Text:
jQuery and Highslide JS 08 January 2008
I'm back! Peterbe.com has been renewed 05 June 2005
Anti-McCain propaganda videos 12 August 2008
Ever wondered how much $87 Billion is? 04 November 2003
Guake, not Yakuake or Yeahconsole 23 January 2010