Last active
October 16, 2024 13:56
-
-
Save vstoykov/1366794 to your computer and use it in GitHub Desktop.
Force Django to use settings.LANGUAGE_CODE for default language instead of request.META['HTTP_ACCEPT_LANGUAGE']
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
@dismine Yes, you're right! 👍
Thank You so much @vstoykov!
thanks, saved my day
Thanks everybody involved!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this version. But it has issue
It will crash with error 'list' object has no attribute 'split'. I think it should be instead