Nasty surprise of Django and gettext

18 January 2009   3 comments   Django

Mind That Age!

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

Powered by Fusion×

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:

I then go ahead and mark my templates and code and run 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/ 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.


Ramiro Morales
Try using


and makemessages -l sv_SE

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


sv-SE will work just fine but you need to name your directory sv_SE instead of sv-SE
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 :)
Thank you for posting a comment

Your email will never ever be published

Related posts

Formatting numeric amounts in Javascript 16 January 2009
Rock stars and their parents 19 January 2009