8

I have been developing for some time in en-gb language code. Now arriving closer to the release date I was going to switch the default language to en-us, but whatever I do the initial request.LANGUAGE_CODE is set to en-gb even for unregistered users.

FYI, I would actually like to keep the time_zone to London and simply change the default language to American English. For now I have changed both just to get it working, but still no joy.

#TIME_ZONE = 'Europe/London'
TIME_ZONE = 'US/Eastern'

LANGUAGE_CODE = 'en-us'
#LANGUAGE_CODE = 'en-gb'

ugettext = lambda s: s

LANGUAGES = (
    ('en', ugettext('American English')),
    ('en-gb', ugettext('British English'))
)

USE_I18N = True
USE_L10N = True
USE_TZ = True

What could I be missing? Thanks

Simeon Visser
  • 118,920
  • 18
  • 185
  • 180
Houman
  • 64,245
  • 87
  • 278
  • 460

4 Answers4

12

LANGUAGE_CODE is only the default when Django can't find what language to use. You probably already have en-gb in your session or a cookie which Django picks up on.

Have a read through How Django discovers language preference for more information on the steps Django takes to determine a request's language.

Flimm
  • 136,138
  • 45
  • 251
  • 267
Simeon Visser
  • 118,920
  • 18
  • 185
  • 180
  • Thanks Simeon, it is strange, even in browser "Private mode", which should not have any cookies I still get en-gb. despite having changed my browser locale to USA as well. The link you sent is for Django 1.3. And the page is removed for 1.4. Strange.. still investigating – Houman Jan 28 '13 at 13:25
  • 1
    For Django 1.4 it can be found here: https://docs.djangoproject.com/en/1.4//topics/i18n/translation/#how-django-discovers-language-preference – Simeon Visser Jan 28 '13 at 13:29
  • Thanks. Despite all my efforts, trying to emulate the American environment here in London (proxy, browser locale language switcher, incognito mode) I didn't succeed and called a friend in US to test the site. And he gets the American English by default. So its all good. :D – Houman Feb 01 '13 at 22:47
2

Have a look at how Django discovers language preference.

In your case, I bet you have LocaleMiddleware enabled, and it's getting your language from the Accept-Language header that your browser sends with every request. You can change that header in your browser's preferences, although many users are unaware of this and stay at whatever the default was on their system. In Firefox, for instance, you can change this at Preferences, Content, Choose (under Languages).

Flimm
  • 136,138
  • 45
  • 251
  • 267
1

Had an issue for a while with this... I later discovered a middleware was missing in my settings.py file... thats -> 'django.middleware.locale.LocaleMiddleware',

How Django discovers language preference

Where to place the middleware

johnfidel
  • 62
  • 3
0

https://github.com/django/django/pull/17151

you find the solution here you need to customize the Local MiddleWare to skip the preferred browser language