Eric
Eric

Reputation: 5101

Django LANGUAGE_CODE = 'en' but displays 'fr'?

I wrote my templates in ENGLISH by using {% trans %} inside.

I decided to translate that into French, so I put that in the settings :

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

LANGUAGES = (
    ('en', _('English')),
    ('fr', _('French')),
)

LANGUAGE_CODE = 'fr'

LOCALE_PATHS = (
    os.path.join(BASE_DIR, 'locale'),
)

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

Then I used makemessages and compilemessages to generated translated strings. And this worked fine ! My website is in French.

But now I would like to get back my site to be in English, So I just change LANGUAGE_CODE to :

LANGUAGE_CODE = 'en'

But my website is still in French ! Even the django-debug-bar is still in French.

The only workaround I found is to comment out the french in LANGUAGES :

LANGUAGES = (
    ('en', _('English')),
    # ('fr', _('French')),
)

Why LANGUAGE_CODE = 'en' does not work ?

Upvotes: 5

Views: 8048

Answers (1)

PRMoureu
PRMoureu

Reputation: 13337

You need to comment or disable 'django.middleware.locale.LocaleMiddleware', in settings.py.

This middleware handles the choice of the language from the request parameters.


Translation documentation :

https://docs.djangoproject.com/en/1.11/topics/i18n/translation/#how-django-discovers-language-preference

Middleware documentation :

https://docs.djangoproject.com/en/1.11/ref/middleware/#module-django.middleware.locale

Upvotes: 10

Related Questions