Server : Apache System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64 User : dh_edsupp ( 6597262) PHP Version : 8.2.26 Disable Function : NONE Directory : /lib/python3/dist-packages/django/middleware/__pycache__/ |
Upload File : |
o 3�a� � @ sl d dl mZ d dlmZ d dlmZ d dlmZmZ d dl m Z d dlmZ d dl mZ G dd � d e�Zd S )� )�settings)� is_language_prefix_patterns_used)�HttpResponseRedirect)�get_script_prefix� is_valid_path)�translation)�patch_vary_headers)�MiddlewareMixinc @ s$ e Zd ZdZeZdd� Zdd� ZdS )�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). c C s^ t |dtj�}t|�\}}tj||d�}t�|j�}|s#|r#|s#tj}t� |� t� � |_d S )N�urlconf)� check_path)�getattrr �ROOT_URLCONFr r �get_language_from_request�get_language_from_path� path_info� LANGUAGE_CODE�activate�get_language)�self�requestr �i18n_patterns_used�prefixed_default_language�language�language_from_path� r �:/usr/lib/python3/dist-packages/django/middleware/locale.py�process_request s z LocaleMiddleware.process_requestc C s� t �� }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||f d�}| �|�S |r`|set|d � |j�d |� |S )Nr i� z/%s%s�/z%s/)�force_append_slashz%s%s/� )zAccept-LanguagezContent-Language)r r r r r r r r �status_coder �APPEND_SLASH�endswithr � get_full_path�replace�response_redirect_classr �headers� setdefault) r r �responser r r r r � language_path� path_valid�path_needs_slash� script_prefix�language_urlr r r �process_response s6 �� � � z!LocaleMiddleware.process_responseN)�__name__� __module__�__qualname__�__doc__r r&