Want more features on Pastebin? Sign Up, it's FREE!
Guest

Language middleware

By: a guest on Nov 6th, 2012  |  syntax: Python  |  size: 0.46 KB  |  views: 39  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.     def process_request(self, request):
  2.         if hasattr(request, 'user'):
  3.             # FIXME: kinda hacky the way it determines user preference
  4.             if not request.user.is_anonymous():
  5.                 pref_lang = request.user.userprofile.language - 1
  6.                 pref_lang_str = settings.LANGUAGES[pref_lang][0]
  7.                 if hasattr(request, 'session'):
  8.                     request.session['django_language'] = pref_lang_str
  9.         return None
clone this paste RAW Paste Data