o
    LDix                     @  s   d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ e
r6d d	lmZ G d
d ded ZdS )    )annotationsN)contextmanager)
ContextVar)Path)TYPE_CHECKING)	LazyProxy)ContextInstanceMixin)	Generatorc                   @  s   e Zd Zdddd,ddZed-ddZejd.ddZed/ddZed0ddZ	d1ddZ
d2ddZed3ddZ	 	!	 d4d5d'd(Z	 	!	 d4d6d*d+Zd S )7I18nenmessages)default_localedomainpath
str | Pathr   strr   returnNonec                C  s2   t || _|| _|| _td|d| _|  | _d S )Naiogram_ctx_locale)default)r   r   r   r   r   
ctx_localefind_localeslocales)selfr   r   r    r   c/var/www/www-root/data/www/77.83.87.30/venv/lib/python3.10/site-packages/aiogram/utils/i18n/core.py__init__   s
   
zI18n.__init__c                 C  s
   | j  S N)r   getr   r   r   r   current_locale   s   
zI18n.current_localevaluec                 C  s   | j | d S r   )r   set)r   r!   r   r   r   r    "   s   localeGenerator[None, None, None]c              	   c  s6    | j |}zdV  W | j | dS | j | w )z6
        Create context with specified locale
        N)r   r"   reset)r   r#   	ctx_tokenr   r   r   
use_locale&   s
   zI18n.use_localeGenerator[I18n, None, None]c              	   c  s0    |  | }z| V  W | | dS | | w )z"
        Use I18n context
        N)set_currentreset_current)r   tokenr   r   r   context1   s
   
zI18n.context"dict[str, gettext.GNUTranslations]c              	   C  s   i }| j  D ]J}| j |  sq| j | d | jd  }| r?|d}t|||j< W d   n1 s9w   Y  q|	d rQd|j d}t
|q|S )zY
        Load all compiled locales from path

        :return: dict with locales
        LC_MESSAGESz.morbNz.pozFound locale 'z$' but this language is not compiled!)r   iterdiris_dirr   existsopengettextGNUTranslationsnamewith_suffixRuntimeError)r   translationsr6   mo_pathfpmsgr   r   r   r   <   s   zI18n.find_localesc                 C  s   |   | _dS )z$
        Hot reload locales
        N)r   r   r   r   r   r   reloadR   s   zI18n.reloadtuple[str, ...]c                 C  s   t | j S )z:
        list of loaded locales

        :return:
        )tupler   keysr   r   r   r   available_localesX   s   zI18n.available_localesN   singularplural
str | Nonenintc                 C  sV   |du r| j }|| jvr|dkr|S |p|S | j| }|du r$||S ||||S )z
        Get text

        :param singular:
        :param plural:
        :param n:
        :param locale:
        :return:
        NrB   )r    r   r4   ngettext)r   rC   rD   rF   r#   
translatorr   r   r   r4   a   s   


zI18n.gettextr   c                 C  s   t | j||||ddS )NF)rC   rD   rF   r#   enable_cache)r   r4   )r   rC   rD   rF   r#   r   r   r   lazy_gettext   s   zI18n.lazy_gettext)r   r   r   r   r   r   r   r   )r   r   )r!   r   r   r   )r#   r   r   r$   )r   r(   )r   r-   )r   r   )r   r>   )NrB   N)
rC   r   rD   rE   rF   rG   r#   rE   r   r   )
rC   r   rD   rE   rF   rG   r#   rE   r   r   )__name__
__module____qualname__r   propertyr    setterr   r'   r,   r   r=   rA   r4   rK   r   r   r   r   r
      s0    



!r
   )
__future__r   r4   
contextlibr   contextvarsr   pathlibr   typingr   aiogram.utils.i18n.lazy_proxyr   aiogram.utils.mixinsr   collections.abcr	   r
   r   r   r   r   <module>   s    