I know it's been more than a year since this question has been answered, but i've ran into a similar problem and after many hours trying to figure out, i've finally come to a deterministic anwser.
Disclaimer: i'm using pt-br because is my mother language, but you can derive this to any language you want
First, what did i do on my django application (assuming you already have created project and app[s] and the current directory is the project dir):
- created locale dir:
mkdir locale
- created a pt_BR locale:
django-admin.py makemessages -l pt_BR
- changed the text inside the created file
- compiled all messages:
django-admin.py compilemessages
- added LOCALE_PATHS variable to django settings:
LOCALE_PATHS =('/path/to/locale_foder',)
After this, my Django app was never being translated. No matter what i did...
According to django documentation (https://docs.djangoproject.com/en/dev/topics/i18n/translation/#how-django-discovers-language-preference) django has a predefined way to find language preferences, and this is how it works:
- django search for the language prefix in the url, for this to work you must be using i18n_patterns in django url.
- if the above fails, search for a variable in user session
- if the above fails, search for a cookie
- if the above fails, use the Accept-Language HTTP header
- if the above fails, use the language specified in homonymous variable in django settings.
I've highlighted number 4 because, in my case, that's the one i'm using. This means my application is dependent on HTTP browser data.
Now, since we are dependent on HTTP data, let's check how the browser behaves. I mainly use chrome and firefox. My chrome has the following language settings on my notebook:
And that is the problem, my Accept-Language HTTP header is sending pt, but i do not have pt locale, i only have a pt-br locale. If it was the other way around, this would work. My conclusion is that one should always have the iso 639-1 codes, and from there use specialisation. For example: i'm now using pt as default for pt-br, and pt-pt for Portugal specific translations.