File manager - Edit - /usr/local/CyberPanel/lib/python3.10/site-packages/django/views/__pycache__/i18n.cpython-310.pyc
Back
o �h�, � @ s� d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZm Z m Z d dlmZm Z d dlmZ d dlmZ d dlmZ d d lmZmZ d d lmZ d dlmZ dZd d� Zdd� ZdZG dd� de�ZG dd� de�Z dS )� N)�apps)�settings)�HttpResponse�HttpResponseRedirect�JsonResponse)�Context�Engine)� translate_url�� get_format)�url_has_allowed_host_and_scheme)�check_for_language�get_language)�DjangoTranslation)�View�languagec C s� | j �d| j�d��}|s| �d�r2t|| �� h| �� d�s2| j�d�}t|| �� h| �� d�s2d}|r8t|�nt dd�}| j dkrq| j �t�}|rqt|�rq|r]t ||�}||kr]t|�}|jtj|tjtjtjtjtjtjd � |S ) a� Redirect to a given URL while setting the chosen language in the session (if enabled) and in a cookie. The URL and the language code need to be specified in the request parameters. Since this view changes how the user will see the rest of the site, it must only be accessed as a POST request. If called as a GET request, it will redirect to the page in the request (the 'next' parameter) without changing any state. �nextz text/html)�url� allowed_hosts� require_https�HTTP_REFERER�/�� )�status�POST)�max_age�path�domain�secure�httponly�samesite)r �get�GET�acceptsr �get_host� is_secure�METAr r �method�LANGUAGE_QUERY_PARAMETERr r � set_cookier �LANGUAGE_COOKIE_NAME�LANGUAGE_COOKIE_AGE�LANGUAGE_COOKIE_PATH�LANGUAGE_COOKIE_DOMAIN�LANGUAGE_COOKIE_SECURE�LANGUAGE_COOKIE_HTTPONLY�LANGUAGE_COOKIE_SAMESITE)�request�next_url�response� lang_code� next_trans� r6 �G/usr/local/CyberPanel/lib/python3.10/site-packages/django/views/i18n.py�set_language sJ ����� � r8 c C s d} dd� | D �S )z5Return all formats strings required for i18n to work.)�DATE_FORMAT�DATETIME_FORMAT�TIME_FORMAT�YEAR_MONTH_FORMAT�MONTH_DAY_FORMAT�SHORT_DATE_FORMAT�SHORT_DATETIME_FORMAT�FIRST_DAY_OF_WEEK�DECIMAL_SEPARATOR�THOUSAND_SEPARATOR�NUMBER_GROUPING�DATE_INPUT_FORMATS�TIME_INPUT_FORMATS�DATETIME_INPUT_FORMATSc S s i | ]}|t |��qS r6 r )�.0�attrr6 r6 r7 � <dictcomp>T s zget_formats.<locals>.<dictcomp>r6 )�FORMAT_SETTINGSr6 r6 r7 �get_formatsB s rK a� {% autoescape off %} 'use strict'; { const globals = this; const django = globals.django || (globals.django = {}); {% if plural %} django.pluralidx = function(n) { const v = {{ plural }}; if (typeof v === 'boolean') { return v ? 1 : 0; } else { return v; } }; {% else %} django.pluralidx = function(count) { return (count == 1) ? 0 : 1; }; {% endif %} /* gettext library */ django.catalog = django.catalog || {}; {% if catalog_str %} const newcatalog = {{ catalog_str }}; for (const key in newcatalog) { django.catalog[key] = newcatalog[key]; } {% endif %} if (!django.jsi18n_initialized) { django.gettext = function(msgid) { const value = django.catalog[msgid]; if (typeof value === 'undefined') { return msgid; } else { return (typeof value === 'string') ? value : value[0]; } }; django.ngettext = function(singular, plural, count) { const value = django.catalog[singular]; if (typeof value === 'undefined') { return (count == 1) ? singular : plural; } else { return value.constructor === Array ? value[django.pluralidx(count)] : value; } }; django.gettext_noop = function(msgid) { return msgid; }; django.pgettext = function(context, msgid) { let value = django.gettext(context + '\x04' + msgid); if (value.includes('\x04')) { value = msgid; } return value; }; django.npgettext = function(context, singular, plural, count) { let value = django.ngettext(context + '\x04' + singular, context + '\x04' + plural, count); if (value.includes('\x04')) { value = django.ngettext(singular, plural, count); } return value; }; django.interpolate = function(fmt, obj, named) { if (named) { return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])}); } else { return fmt.replace(/%s/g, function(match){return String(obj.shift())}); } }; /* formatting library */ django.formats = {{ formats_str }}; django.get_format = function(format_type) { const value = django.formats[format_type]; if (typeof value === 'undefined') { return format_type; } else { return value; } }; /* add to global namespace */ globals.pluralidx = django.pluralidx; globals.gettext = django.gettext; globals.ngettext = django.ngettext; globals.gettext_noop = django.gettext_noop; globals.pgettext = django.pgettext; globals.npgettext = django.npgettext; globals.interpolate = django.interpolate; globals.get_format = django.get_format; django.jsi18n_initialized = true; } }; {% endautoescape %} c @ s` e Zd ZdZdZdZdd� Zdd� Zedd � �Z ed d� �Z dd � Zdd� Zdd� Z dd� ZdS )�JavaScriptCataloga Return the selected language catalog as a JavaScript library. Receive the list of packages to check for translations in the `packages` kwarg either from the extra dictionary passed to the path() function or as a plus-sign delimited string from the request. Default is 'django.conf'. You can override the gettext domain for this view, but usually you don't want to do that as JavaScript messages go to the djangojs domain. This might be needed if you deliver your JavaScript source from Django templates. �djangojsNc O sp t � }|�d| j�}|�dd�}|r|�d�n| j}|r!| �|�nd }t|||d�| _| jdi |��}| � |�S )Nr �packages� �+)r � localedirsr6 ) r r! r �splitrN � get_pathsr �translation�get_context_data�render_to_response) �selfr1 �args�kwargs�localer rN �paths�contextr6 r6 r7 r! � s zJavaScriptCatalog.getc sf dd� t �� D �� � fdd�|D �}t|�t|�k r,� fdd�|D �}tdd�|� ��dd� |D �S ) Nc S s i | ]}|j |�qS r6 )�name)rG � app_configr6 r6 r7 rI � s �z/JavaScriptCatalog.get_paths.<locals>.<dictcomp>c s g | ] }|� v r� | �qS r6 r6 �rG �p��allowable_packagesr6 r7 � <listcomp>� s z/JavaScriptCatalog.get_paths.<locals>.<listcomp>c s g | ]}|� vr|�qS r6 r6 r_ ra r6 r7 rc � � z4Invalid package(s) provided to JavaScriptCatalog: %s�,c S s g | ] }t j�|jd ��qS )rZ )�osr �join)rG �appr6 r6 r7 rc � s )r �get_app_configs�len� ValueErrorrg )rW rN �app_configs�excludedr6 ra r7 rS � s � ���zJavaScriptCatalog.get_pathsc C s&