Permalink
Browse files

Check session locale in middleware

  • Loading branch information...
1 parent 1581676 commit baaf82556fcfbf7ccfca3f3e9ef8ab0ccb0fcf52 @amarandon amarandon committed Feb 14, 2012
Showing with 13 additions and 7 deletions.
  1. +13 −7 localeurl/middleware.py
View
@@ -38,13 +38,19 @@ def __init__(self):
def process_request(self, request):
locale, path = utils.strip_path(request.path_info)
- if localeurl_settings.USE_ACCEPT_LANGUAGE and not locale:
- accept_langs = filter(lambda x: x, [utils.supported_language(lang[0])
- for lang in
- parse_accept_lang_header(
- request.META.get('HTTP_ACCEPT_LANGUAGE', ''))])
- if accept_langs:
- locale = accept_langs[0]
+ if not locale:
+ if localeurl_settings.USE_SESSION:
+ slocale = request.session.get('locale')
+ if slocale and utils.supported_language(slocale):
+ locale = slocale
+ elif localeurl_settings.USE_ACCEPT_LANGUAGE:
+ accept_lang_header = request.META.get('HTTP_ACCEPT_LANGUAGE', '')
+ header_langs = parse_accept_lang_header(accept_lang_header)
+ accept_langs = filter(lambda x: x,
+ [utils.supported_language(lang[0])
+ for lang in header_langs])
+ if accept_langs:
+ locale = accept_langs[0]
locale_path = utils.locale_path(path, locale)
if locale_path != request.path_info:
locale_url = utils.add_script_prefix(locale_path)

0 comments on commit baaf825

Please sign in to comment.