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] locale_path = utils.locale_path(path, locale) if locale_path != request.path_info: if request.META.get("QUERY_STRING", ""): locale_path = "%s?%s" % (locale_path, request.META['QUERY_STRING']) locale_url = utils.add_script_prefix(locale_path) # @@@ iri_to_uri for Django 1.0; 1.1+ do it in HttpResp...Redirect return HttpResponsePermanentRedirect(iri_to_uri(locale_url)) request.path_info = path if not locale: try: locale = request.LANGUAGE_CODE except AttributeError: locale = settings.LANGUAGE_CODE translation.activate(locale) request.LANGUAGE_CODE = translation.get_language()
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] locale_path = utils.locale_path(path, locale) if locale_path != request.path_info: if request.META.get("QUERY_STRING", ""): locale_path = "%s?%s" % (locale_path, request.META['QUERY_STRING']) locale_url = utils.add_script_prefix(locale_path) redirect_class = HttpResponsePermanentRedirect if not localeurl_settings.LOCALE_REDIRECT_PERMANENT: redirect_class = HttpResponseRedirect # @@@ iri_to_uri for Django 1.0; 1.1+ do it in HttpResp...Redirect return redirect_class(iri_to_uri(locale_url)) request.path_info = path if not locale: try: locale = request.LANGUAGE_CODE except AttributeError: locale = settings.LANGUAGE_CODE translation.activate(locale) request.LANGUAGE_CODE = translation.get_language()
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] locale_path = utils.locale_path(path, locale) if locale_path != request.path_info: locale_url = utils.add_script_prefix(locale_path) qs = request.META.get("QUERY_STRING", "") if qs: # Force this to remain a byte-string by encoding locale_path # first to avoid Unicode tainting - downstream will need to # handle the job of handling in-the-wild character encodings: locale_url = "%s?%s" % (locale_path.encode("utf-8"), qs) redirect_class = HttpResponsePermanentRedirect if not localeurl_settings.LOCALE_REDIRECT_PERMANENT: redirect_class = HttpResponseRedirect # @@@ iri_to_uri for Django 1.0; 1.1+ do it in HttpResp...Redirect return redirect_class(iri_to_uri(locale_url)) request.path_info = path if not locale: try: locale = request.LANGUAGE_CODE except AttributeError: locale = settings.LANGUAGE_CODE translation.activate(locale) request.LANGUAGE_CODE = translation.get_language()
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] locale_path = utils.locale_path(path, locale) if locale_path != request.path_info: locale_url = utils.add_script_prefix(locale_path) qs = request.META.get("QUERY_STRING", "") if qs: # Force this to remain a byte-string by encoding locale_path # first to avoid Unicode tainting - downstream will need to # handle the job of handling in-the-wild character encodings: locale_url = "%s?%s" % (locale_path.encode("utf-8"), qs) redirect_class = HttpResponsePermanentRedirect if not localeurl_settings.LOCALE_REDIRECT_PERMANENT: redirect_class = HttpResponseRedirect # @@@ iri_to_uri for Django 1.0; 1.1+ do it in HttpResp...Redirect return redirect_class(iri_to_uri(locale_url)) request.path_info = path if not locale: try: locale = request.LANGUAGE_CODE except AttributeError: locale = settings.LANGUAGE_CODE translation.activate(locale) request.LANGUAGE_CODE = translation.get_language()
def process_request(self, request): hostname = request.get_host().split(":")[0] locale, path = utils.strip_path(request.path_info) if localeurl_settings.USE_SESSION and not locale: slocale = request.session.get('django_language') if slocale and utils.supported_language(slocale): locale = slocale if localeurl_settings.USE_ACCEPT_LANGUAGE and not locale: accept_lang_header = request.META.get('HTTP_ACCEPT_LANGUAGE', '') header_langs = parse_accept_lang_header(accept_lang_header) accept_langs = filter( None, [utils.supported_language(lang[0]) for lang in header_langs]) if accept_langs: locale = accept_langs[0] if hasattr(request, 'urlconf') and request.urlconf is not None: urlconf = request.urlconf else: urlconf = get_urlconf() locale_path = utils.locale_path(path, locale, host=hostname, urlconf=urlconf) # locale case might be different in the two paths, that doesn't require # a redirect (besides locale they'll be identical anyway) if locale_path.lower() != request.path_info.lower(): locale_url = utils.add_script_prefix(locale_path) qs = request.META.get("QUERY_STRING", "") if qs: # Force this to remain a byte-string by encoding locale_path # first to avoid Unicode tainting - downstream will need to # handle the job of handling in-the-wild character encodings: locale_url = "%s?%s" % (locale_path.encode("utf-8"), qs) redirect_class = HttpResponsePermanentRedirect if not localeurl_settings.LOCALE_REDIRECT_PERMANENT: redirect_class = HttpResponseRedirect # @@@ iri_to_uri for Django 1.0; 1.1+ do it in HttpResp...Redirect return redirect_class(iri_to_uri(locale_url)) request.path_info = path if not locale: try: locale = request.LANGUAGE_CODE except AttributeError: locale = settings.LANGUAGE_CODE translation.activate(locale) request.LANGUAGE_CODE = translation.get_language()
def process_request(self, request): hostname = request.get_host().split(":")[0] locale, path = utils.strip_path(request.path_info) if localeurl_settings.USE_SESSION and not locale: slocale = request.session.get('django_language') if slocale and utils.supported_language(slocale): locale = slocale if localeurl_settings.USE_ACCEPT_LANGUAGE and not locale: accept_lang_header = request.META.get('HTTP_ACCEPT_LANGUAGE', '') header_langs = parse_accept_lang_header(accept_lang_header) accept_langs = filter( None, [utils.supported_language(lang[0]) for lang in header_langs] ) if accept_langs: locale = accept_langs[0] if hasattr(request, 'urlconf') and request.urlconf is not None: urlconf = request.urlconf else: urlconf = get_urlconf() locale_path = utils.locale_path(path, locale, host=hostname, urlconf=urlconf) # locale case might be different in the two paths, that doesn't require # a redirect (besides locale they'll be identical anyway) if locale_path.lower() != request.path_info.lower(): locale_url = utils.add_script_prefix(locale_path) qs = request.META.get("QUERY_STRING", "") if qs: # Force this to remain a byte-string by encoding locale_path # first to avoid Unicode tainting - downstream will need to # handle the job of handling in-the-wild character encodings: locale_url = "%s?%s" % (locale_path.encode("utf-8"), qs) redirect_class = HttpResponsePermanentRedirect if not localeurl_settings.LOCALE_REDIRECT_PERMANENT: redirect_class = HttpResponseRedirect # @@@ iri_to_uri for Django 1.0; 1.1+ do it in HttpResp...Redirect return redirect_class(iri_to_uri(locale_url)) request.path_info = path if not locale: try: locale = request.LANGUAGE_CODE except AttributeError: locale = settings.LANGUAGE_CODE translation.activate(locale) request.LANGUAGE_CODE = translation.get_language()