
     jh                        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
rd d	lmZ  G d
 ded         Zy)    )annotationsN)contextmanager)
ContextVar)Path)TYPE_CHECKING)	LazyProxy)ContextInstanceMixin)	Generatorc                      e Zd Zddd	 	 	 	 	 	 	 ddZedd       Zej                  dd       Zedd       Zedd       Z	dd	Z
dd
Zedd       Z	 	 	 d	 	 	 	 	 	 	 	 	 ddZ	 	 	 d	 	 	 	 	 	 	 	 	 ddZy)I18nenmessages)default_localedomainc                   t        |      j                         | _        || _        || _        t        d|      | _        | j                         | _        y )Naiogram_ctx_locale)default)	r   resolvepathr   r   r   
ctx_localefind_localeslocales)selfr   r   r   s       J/var/www/html/venv/lib/python3.12/site-packages/aiogram/utils/i18n/core.py__init__zI18n.__init__   sF     J&&(	,$%9>R((*    c                6    | j                   j                         S N)r   getr   s    r   current_localezI18n.current_locale   s    ""$$r   c                :    | j                   j                  |       y r   )r   set)r   values     r   r!   zI18n.current_locale"   s    E"r   c              #     K   | j                   j                  |      }	 d | j                   j                  |       y# | j                   j                  |       w xY ww)z6
        Create context with specified locale
        N)r   r#   reset)r   locale	ctx_tokens      r   
use_localezI18n.use_locale&   sH     
 OO''/		-OO!!),DOO!!),s   A? AAAc              #     K   | j                  |       }	 |  | j                  |       y# | j                  |       w xY ww)z"
        Use I18n context
        N)set_currentreset_current)r   tokens     r   contextzI18n.context1   s>     
   &	&Ju%Du%s   A+ A>Ac                   i }| j                   j                         D ]  }|j                         s|dz  | j                  dz   z  }|j	                         r=|j                  d      5 }t        j                  |      ||j                  <   ddd       v|j                  d      j	                         sd|j                   d}t        |       |S # 1 sw Y   xY w)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   translationsr8   mo_pathfpmsgs         r   r   zI18n.find_locales<   s     <>II%%' 
	(D;;=]*dkkE.ABG~~\\$' J2.5.E.Eb.IL+J J$$U+224&tyyk1UV"3''
	( J Js   '#CC	c                .    | j                         | _        y)z$
        Hot reload locales
        N)r   r   r    s    r   reloadzI18n.reloadR   s     ((*r   c                H    t        | j                  j                               S )z:
        list of loaded locales

        :return:
        )tupler   keysr    s    r   available_localeszI18n.available_localesX   s     T\\&&())r   Nc                    || j                   }|| j                  vr|dk(  r|S |xs |S | j                  |   }||j                  |      S |j                  |||      S )z
        Get text

        :param singular:
        :param plural:
        :param n:
        :param locale:
        :return:
           )r!   r   r6   ngettext)r   singularpluralnr'   
translators         r   r6   zI18n.gettexta   sp      >((F%Av%X%\\&)
>%%h//""8VQ77r   c                8    t        | j                  ||||d      S )NF)rH   rI   rJ   r'   enable_cache)r   r6   )r   rH   rI   rJ   r'   s        r   lazy_gettextzI18n.lazy_gettext   s'     LL
 	
r   )r   z
str | Pathr   strr   rO   returnNone)rP   rO   )r$   rO   rP   rQ   )r'   rO   rP   zGenerator[None, None, None])rP   zGenerator[I18n, None, None])rP   z"dict[str, gettext.GNUTranslations])rP   rQ   )rP   ztuple[str, ...])NrF   N)
rH   rO   rI   
str | NonerJ   intr'   rR   rP   rO   )
rH   rO   rI   rR   rJ   rS   r'   rR   rP   r   )__name__
__module____qualname__r   propertyr!   setterr   r)   r.   r   r@   rD   r6   rN    r   r   r   r      s,   
 # + + 	+
 + 
+ % % # # - - & &,+ * * "!88 8 	8
 8 
8B "!

 
 	

 
 

r   r   )
__future__r   r6   
contextlibr   contextvarsr   pathlibr   typingr   aiogram.utils.i18n.lazy_proxyr   aiogram.utils.mixinsr	   collections.abcr
   r   rY   r   r   <module>rb      s7    "  % "    3 5)}
' }
r   