1 # -*- coding: utf-8 -*-
2 # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.utils import translation
6 from django.conf import settings
7 from django.http import Http404
10 class URLLocaleMiddleware(object):
11 """Decides which translation to use, based on path only."""
13 def process_request(self, request):
14 language = translation.get_language_from_path(request.path_info)
15 if language == settings.LANGUAGE_CODE:
18 translation.activate(language)
19 request.LANGUAGE_CODE = translation.get_language()
21 def process_response(self, request, response):
22 language = translation.get_language()
23 translation.deactivate()
24 if 'Content-Language' not in response:
25 response['Content-Language'] = language