Skip to content

Instantly share code, notes, and snippets.

@breyten
Created December 11, 2013 11:49
Show Gist options
  • Save breyten/7909059 to your computer and use it in GitHub Desktop.
Save breyten/7909059 to your computer and use it in GitHub Desktop.
Modify the locale middleware in python to not look at the HTTP_ACCEPT_LANGUAGE header (and just use the language specified in the settings or the user's preferences)
import os
import sys
import re
from django.utils import translation
from django.middleware.locale import LocaleMiddleware
class LocaleNoHTTPAcceptMiddleware(LocaleMiddleware):
def process_request(self, request):
request.LANGUAGE_CODE = translation.get_language()
# Now just remember to do the following in your settings:
# MIDDLEWARE_CLASSES = [
# ...
# 'django.middleware.locale.LocaleMiddleware',
# '<appname>.middleware.LocaleNoHTTPAcceptMiddleware',
# ...
# ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment