mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Merged i18n branch into the trunk! Fixes #65, and perhaps some others. NB: this means that the i18n branch is now obsolete and will be made read-only.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1068 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
24
django/middleware/locale.py
Normal file
24
django/middleware/locale.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"this is the locale selecting middleware that will look at accept headers"
|
||||
|
||||
from django.utils.cache import patch_vary_headers
|
||||
from django.utils import translation
|
||||
|
||||
class LocaleMiddleware:
|
||||
"""
|
||||
This is a very simple middleware that parses a request
|
||||
and decides what translation object to install in the current
|
||||
thread context. This allows pages to be dynamically
|
||||
translated to the language the user desires (if the language
|
||||
is available, of course).
|
||||
"""
|
||||
|
||||
def process_request(self, request):
|
||||
language = translation.get_language_from_request(request)
|
||||
translation.activate(language)
|
||||
request.LANGUAGE_CODE = translation.get_language()
|
||||
|
||||
def process_response(self, request, response):
|
||||
patch_vary_headers(response, ('Accept-Language',))
|
||||
translation.deactivate()
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user