If I place the locale codes in the URL, then I get the correct locale response:

http://localhost:8000/fr-ca/ I get fr-ca text back
http://localhost:8000/fr/ I get fr text back
http://localhost:8000/en/ I get en text back
http://localhost:8000/en-gb/ I get en-gb text back
http://localhost:8000/es-us/ I get es-us text back
http://localhost:8000/es/ I get es text back
http://localhost:8000/ I get en text back _(Default in settings.py)_

en-gb works as expected, and in the last request is returned instead of the higher precedence fr-ca.

Am I just missing something, or do fr-ca/es-us just not work with Django?

(** I also sent in the default django_language cookie, and everything works as expected, so it looks like I'm only experiencing the issue when using the Accept-Language header. **)

UPDATE - The short and sweet answer was already provided by @ilvar

Awright, I finally dug down into Django source (Since it's awesomely open source, and all)

The file [django/utils/translation/trans_real.py][1] is where I found, verified, the answer.

The path is set to the conf/locale directory of the Django install (in site-packages) and dirname is the locale name from the request, in my case fr-ca. So, if the Django install doesn't contain the locale from the request, which it doesn't have fr-ca, it will revert to one that is, fr.

Just above the snippet the language is checked for within the URL first, if you're using i18n routes, and then within the language cookie. If it exists in either then that language code is returned immediately, so it doesn't matter if the language doesn't exist within the Django install.

Handling it differently for 2/3 scenarios is what threw me off, but makes some sense since the browser could send anything, but if you've set a cookie|url then at that point it's your issue.

Thanks @ilvar for the answer, even though I questioned it ;)All I did was just copy the fr to fr_CA, within Django's locales, and voila...

We don't have the admin enabled for this site. All of our translations are created from scratch, so we don't need anything from the existing ones within the admin side. We have all of the translations working when using either the cookie and/or URL, just not with the Accept-Language when it's fr-ca or es-us. All of the others work as expected. So basically Django redirects to the appropriate URLs when the locale is set in the cookie, but not so with only the Accept-Language header.
–
JustinMay 25 '12 at 17:01

1

I think it skips Accept-Language if that language code is not found in django's locale library.
–
ilvarMay 26 '12 at 5:37

You're right; I was just being stubborn in thinking that since it worked with URLs and Cookies that there must be something else going on. Thanks for your answer =)
–
JustinMay 28 '12 at 5:59