Django

Code

root/django/branches/newforms-admin/django/middleware/locale.py

Revision 4265, 0.9 kB (checked in by adrian, 2 years ago)

Fixed #3191 -- Set 'svn:eol-style native' on the files that didn't have it. Thanks, jjl@pobox.com

  • Property svn:eol-style set to native
Line 
1 "this is the locale selecting middleware that will look at accept headers"
2
3 from django.utils.cache import patch_vary_headers
4 from django.utils import translation
5
6 class LocaleMiddleware(object):
7     """
8     This is a very simple middleware that parses a request
9     and decides what translation object to install in the current
10     thread context. This allows pages to be dynamically
11     translated to the language the user desires (if the language
12     is available, of course).
13     """
14
15     def process_request(self, request):
16         language = translation.get_language_from_request(request)
17         translation.activate(language)
18         request.LANGUAGE_CODE = translation.get_language()
19
20     def process_response(self, request, response):
21         patch_vary_headers(response, ('Accept-Language',))
22         response['Content-Language'] = translation.get_language()
23         translation.deactivate()
24         return response
Note: See TracBrowser for help on using the browser.