• Home
  • Django
  • Language setting based on setting.LANGUAGE_CODE not on browser setting

Language setting based on setting.LANGUAGE_CODE not on browser setting

linkaiyi
Follow

language middleware to use setting as default

This middleware should be put in front of local middleware

try:
    from django.utils.deprecation import MiddlewareMixin
except ImportError:
    MiddlewareMixin = object


class ForceDefaultLanguageMiddleware(MiddlewareMixin):
    """
    Ignore Accept-Language HTTP headers

    This will force the I18N machinery to always choose settings.LANGUAGE_CODE
    as the default initial language, unless another one is set via sessions or cookies

    Should be installed *before* any middleware that checks request.META['HTTP_ACCEPT_LANGUAGE'],
    namely django.middleware.locale.LocaleMiddleware
    """
    def process_request(self, request):
        if 'HTTP_ACCEPT_LANGUAGE' in request.META:
            del request.META['HTTP_ACCEPT_LANGUAGE']
Object has 0 attachments

Was this article helpful?

This article is viewed 9 times!

Recent Viewed Articles

Related Articles

0 Comments

Leave a Comment

Support