Django default language

I have a django application for which the default language is set to French. All translation lines in the code and html pages are in French. Switching between different languages ​​works great. But now I need to hide the French language, so I changed LANGUAGE_CODE to "en-us", but the default page is always displayed in French, did I miss something?

thank

+5
source share
4 answers

I ran into this problem quite recently, here is how I managed to fix it without changing the language of the language version of the browser:

LANGUAGE_CODE, , :

from django.conf import settings
from django.utils import translation

class ForceLangMiddleware:

    def process_request(self, request):
        request.LANG = getattr(settings, 'LANGUAGE_CODE', settings.LANGUAGE_CODE)
        translation.activate(request.LANG)
        request.LANGUAGE_CODE = request.LANG

middleware.py (, main), main.middleware.ForceLangMiddleware MIDDLEWARE_CLASSES

+7

... , - , Django , .

, , , , , , .

+3

settings.py LANGUAGES .

LANGUAGES = (
    ('en', gettext('English')),
    ('sv', gettext('Swedish')),
    ('no', gettext('Norwegian')),
)

Django Multilingual, DEFAULT_LANGUAGE:

DEFAULT_LANGUAGE = 1 # the first one in the list
+1

I found this https://gist.github.com/vstoykov/1366794 . It forces the I18N equipment to select parameters. LANGUAGE_CODE as the default source language.

+1
source

All Articles