summaryrefslogtreecommitdiffstats
path: root/askbot/middleware
diff options
context:
space:
mode:
authorAdolfo Fitoria <adolfo.fitoria@gmail.com>2012-04-03 11:55:08 -0600
committerAdolfo Fitoria <adolfo.fitoria@gmail.com>2012-04-03 11:55:08 -0600
commit43835e50fa627c1ed485b96ce0404d18b3ffb1db (patch)
tree85e44f3a163581791726374e04c3c5639889c843 /askbot/middleware
parent4982dfa7567b7ecbbd8bef246c75927a50fe3b26 (diff)
downloadaskbot-43835e50fa627c1ed485b96ce0404d18b3ffb1db.tar.gz
askbot-43835e50fa627c1ed485b96ce0404d18b3ffb1db.tar.bz2
askbot-43835e50fa627c1ed485b96ce0404d18b3ffb1db.zip
added language selection into livesettings, needs more testing
Diffstat (limited to 'askbot/middleware')
-rw-r--r--askbot/middleware/locale.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/askbot/middleware/locale.py b/askbot/middleware/locale.py
new file mode 100644
index 00000000..c92e977a
--- /dev/null
+++ b/askbot/middleware/locale.py
@@ -0,0 +1,26 @@
+"Taken from django.middleware.locale: 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
+from askbot.conf import settings
+
+class LocaleMiddleware(object):
+ """
+ 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 = settings.ASKBOT_LANGUAGE
+ translation.activate(language)
+ request.LANGUAGE_CODE = translation.get_language()
+
+ def process_response(self, request, response):
+ patch_vary_headers(response, ('Accept-Language',))
+ if 'Content-Language' not in response:
+ response['Content-Language'] = translation.get_language()
+ translation.deactivate()
+ return response