o 3a @slddlmZddlmZddlmZddlmZmZddl m Z ddl m Z ddl mZGdd d eZd S) )settings) is_language_prefix_patterns_used)HttpResponseRedirect)get_script_prefix is_valid_path) translation)patch_vary_headers)MiddlewareMixinc@s$eZdZdZeZddZddZdS)LocaleMiddlewarez Parse a request and decide what translation object to install in the current thread context. This allows pages to be dynamically translated to the language the user desires (if the language is available). cCs^t|dtj}t|\}}tj||d}t|j}|s#|r#|s#tj}t |t |_dS)Nurlconf) check_path) getattrr ROOT_URLCONFrrget_language_from_requestget_language_from_path path_info LANGUAGE_CODEactivate get_language)selfrequestr i18n_patterns_usedprefixed_default_languagelanguagelanguage_from_pathr:/usr/lib/python3/dist-packages/django/middleware/locale.pyprocess_requests    z LocaleMiddleware.process_requestc Cst}t|j}t|dtj}t|\}}|jdkr\|s\|r\|r\d||jf}t ||} | o@tj o@| d o@t d||} | sE| r\t } |j | d| d| |fd} || S|r`|set|d |jd ||S) Nr iz/%s%s/z%s/)force_append_slashz%s%s/)zAccept-LanguagezContent-Language)rrrrr rrr status_coder APPEND_SLASHendswithr get_full_pathreplaceresponse_redirect_classrheaders setdefault) rrresponserrr rr language_path path_validpath_needs_slash script_prefix language_urlrrrprocess_responses6        z!LocaleMiddleware.process_responseN)__name__ __module__ __qualname____doc__rr&rr/rrrrr s  r N) django.confrdjango.conf.urls.i18nr django.httpr django.urlsrr django.utilsrdjango.utils.cacherdjango.utils.deprecationr r rrrrs