o
    çûõjh  ã                   @  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  s6   t |ƒ ¡ | _|| _|| _td|d�| _|  ¡ | _d S )NÚaiogram_ctx_locale)Údefault)	r   Úresolver   r   r   r   Ú
ctx_localeÚfind_localesÚlocales)Úselfr   r   r   © r   úJ/opt/steambot/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 ]D}| ¡ sq|d | jd  }| ¡ r9| d¡�}t |¡||j< W d  ƒ n1 s3w   Y  q| 	d¡ ¡ rKd|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   Útranslationsr7   Ú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:
        NrC   )r!   r   r5   Úngettext)r   rD   rE   rG   r$   Ú
translatorr   r   r   r5   a   s   


zI18n.gettextr   c                 C  s   t | j||||dd�S )NF)rD   rE   rG   r$   Úenable_cache)r   r5   )r   rD   rE   rG   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?   )NrC   N)
rD   r   rE   rF   rG   rH   r$   rF   r   r   )
rD   r   rE   rF   rG   rH   r$   rF   r   r   )Ú__name__Ú
__module__Ú__qualname__r   Úpropertyr!   Úsetterr   r(   r-   r   r>   rB   r5   rL   r   r   r   r   r
      s0    û



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