<commit_before>from django.shortcuts import redirect
from django.utils import translation
from django.conf import settings


class LocaleMiddleware(object):
    """
    Middleware for changing language
    """

    def process_request(self, request):
        """
        If lang is found in Get, changes language to selected one
        :param request: django request
        :return: if lang found, redirects back to view but without get params
        """

        if 'lang' in request.GET:
            # Get selected language and current view
            language = request.GET.get('lang', False)
            current_view = request.META.get('PATH_INFO', '/')

            # Checks that selected language code is supported
            possible_languages = settings.LANGUAGES
            for possible_lang in possible_languages:
                if language in possible_lang:
                    # Change active language
                    request.session[translation.LANGUAGE_SESSION_KEY] = language
                    request.COOKIES[settings.LANGUAGE_COOKIE_NAME] = language
                    translation.activate(language)
                    break

            return redirect(current_view)<commit_msg>Fix lang change<commit_after>from django.shortcuts import redirect
from django.utils import translation
from django.conf import settings
from django.core.urlresolvers import resolve, Resolver404
from djangocms_siteselector.helpers import get_current_site


class LocaleMiddleware(object):
    """
    Middleware for changing language
    """

    def process_request(self, request):
        """
        If lang is found in Get, changes language to selected one
        :param request: django request
        :return: if lang found, redirects back to view but without get params
        """

        if 'lang' in request.GET:
            # Get selected language and current view
            language = request.GET.get('lang', False)
            current_site = get_current_site()

            # Checks that selected language code is supported
            possible_languages = settings.LANGUAGES
            for possible_lang in possible_languages:
                if language in possible_lang:
                    # Change active language
                    request.session[translation.LANGUAGE_SESSION_KEY] = language
                    request.COOKIES[settings.LANGUAGE_COOKIE_NAME] = language
                    translation.activate(language)
                    break

            try:
                resolve(request.path)
                return redirect(request.path)
            except Resolver404:
                return redirect('/{0}'.format(current_site.slug))
{'fraction_non_alphanumeric': 0.061498322773015285, 'fraction_numerical': 0.002609019754006709, 'mean_word_length': 2.128205128205128, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2722936', 'n_tokens_mistral': 643, 'n_tokens_neox': 612, 'n_words': 198}