o
    Ni                     @  s<  U d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	 ddl
mZ er9ddlZddlmZmZ ddl
mZ G d	d
 d
Zi Zded< 		d2d3ddZe	e	eZ		d4d5ddZ	d2d6ddZ	d2d7d!d"Zd8d9d$d%ZedZedd&Zed'ed(ed)ed*ed+ed,ed-ed.ed/ed0d1
ZdS ):zLocale utilities.    )annotationsN)NullTranslationstranslation)path)TYPE_CHECKING)CallableIterable)Anyc                   @  s   e Zd ZdZdZd?d	d
Zd@ddZdAddZdBddZdCddZ	dDddZ
dEddZd@ddZdFdd ZdFd!d"ZdFd#d$ZdFd%d&ZdGd'd(ZdGd)d*ZdHd,d-ZdId0d1ZdJd3d4ZdKd6d7ZdHd8d9ZdLd<d=Zd>S )M_TranslationProxyz
    The proxy implementation attempts to be as complete as possible, so that
    the lazy objects should mostly work as expected, for example for sorting.
    
_catalogue
_namespace_message	cataloguestr	namespacemessagereturnNonec                 C  s   || _ || _|| _d S Nr   )selfr   r   r    r   J/home/ubuntu/.local/lib/python3.10/site-packages/sphinx/locale/__init__.py__init__   s   
z_TranslationProxy.__init__c                 C  s4   zt | j| jf | jW S  ty   | j Y S w r   )translatorsr   r   gettextr   KeyErrorr   r   r   r   __str__   s
   
z_TranslationProxy.__str__	list[str]c                 C  s   t tS r   )dirr   r   r   r   r   __dir__%   s   z_TranslationProxy.__dir__namer	   c                 C  s   t |  |S r   )getattrr   )r   r"   r   r   r   __getattr__(   s   z_TranslationProxy.__getattr__tuple[str, str, str]c                 C  s   | j | j| jfS r   r   r   r   r   r   __getstate__+   s   z_TranslationProxy.__getstate__tupc                 C  s   |\| _ | _| _d S r   r   )r   r'   r   r   r   __setstate__.   s   z_TranslationProxy.__setstate__c                 C  s   t | j| j| jS r   )r
   r   r   r   r   r   r   r   __copy__1   s   z_TranslationProxy.__copy__c                 C  sJ   zd|   W S  ty$   | jjd| j d| j d| j d  Y S w )Ni(z, ))r   	Exception	__class____name__r   r   r   r   r   r   r   __repr__4   s   z_TranslationProxy.__repr__otherc                 C  s   |   | S r   r   r   r1   r   r   r   __add__=      z_TranslationProxy.__add__c                 C  s   ||    S r   r2   r3   r   r   r   __radd__@   r5   z_TranslationProxy.__radd__c                 C  s   |   | S r   r2   r3   r   r   r   __mod__C   r5   z_TranslationProxy.__mod__c                 C  s   ||    S r   r2   r3   r   r   r   __rmod__F   r5   z_TranslationProxy.__rmod__c                 C  s   |   | S r   r2   r3   r   r   r   __mul__I   r5   z_TranslationProxy.__mul__c                 C  s   ||    S r   r2   r3   r   r   r   __rmul__L   r5   z_TranslationProxy.__rmul__intc                 C     t |  S r   )hashr   r   r   r   r   __hash__O   r5   z_TranslationProxy.__hash__objectboolc                 C  s   |   |kS r   r2   r3   r   r   r   __eq__R   r5   z_TranslationProxy.__eq__stringc                 C  s   |   |k S r   r2   )r   rB   r   r   r   __lt__U   r5   z_TranslationProxy.__lt__charc                 C  s   ||   v S r   r2   )r   rD   r   r   r   __contains__X   r5   z_TranslationProxy.__contains__c                 C  r<   r   )lenr   r   r   r   r   __len__[   r5   z_TranslationProxy.__len__indexint | slicec                 C  s   |   | S r   r2   )r   rH   r   r   r   __getitem__^   r5   z_TranslationProxy.__getitem__N)r   r   r   r   r   r   r   r   )r   r   )r   r   )r"   r   r   r	   )r   r%   )r'   r%   r   r   )r   r
   )r1   r   r   r   )r1   r	   r   r   )r   r;   )r1   r?   r   r@   )rB   r   r   r@   )rD   r   r   r@   )rH   rI   r   r   )r/   
__module____qualname____doc__	__slots__r   r   r!   r$   r&   r(   r)   r0   r4   r6   r7   r8   r9   r:   r>   rA   rC   rE   rG   rJ   r   r   r   r   r
      s.    








	









r
   z'dict[tuple[str, str], NullTranslations]r   sphinxgenerallocale_dirs'Iterable[str | os.PathLike[str] | None]language
str | Nonecatalogr   r   r   tuple[NullTranslations, bool]c           	   	   C  s   t ||f}|jtu rd}|r|g}nd}| D ] }zt|||d}|du r)|}n|| W q ty8   Y qw |dur@d}nt }d}|t ||f< ||fS )a  Look for message catalogs in `locale_dirs` and *ensure* that there is at
    least a NullTranslations catalog set in `translators`. If called multiple
    times or if several ``.mo`` files are found, their contents are merged
    together (thus making ``init`` reentrant).
    N)	localedir	languagesTF)r   getr.   r   r   add_fallbackr-   )	rQ   rS   rU   r   
translatorrX   dir_transhas_translationr   r   r   inite   s,   

r_   
locale_dirc                 C  sX   | du rt } tjdkrd}nz
ttj\}}W n ty#   d}Y nw t| g||dS )z>Initialize locale for console.

    .. versionadded:: 1.8
    Nwin32console)_LOCALE_DIRsysplatformlocale	getlocaleLC_MESSAGESAttributeErrorr_   )r`   rU   rS   _r   r   r   init_console   s   
rk   r   c                 C  s   t || ft S r   )r   rY   r   rU   r   r   r   r   get_translator   s   rm   r@   c                 C  s   || ft v S r   )r   rl   r   r   r   is_translator_registered   s   rn   Callable[[str], str]c                   s   d fdd}|S )aA  Get a translation function based on the *catalog* and *namespace*.

    The extension can use this API to translate the messages on the
    extension::

        import os
        from sphinx.locale import get_translation

        MESSAGE_CATALOG_NAME = 'myextension'  # name of *.pot, *.po and *.mo files
        _ = get_translation(MESSAGE_CATALOG_NAME)
        text = _('Hello Sphinx!')


        def setup(app):
            package_dir = os.path.abspath(os.path.dirname(__file__))
            locale_dir = os.path.join(package_dir, 'locales')
            app.add_message_catalog(MESSAGE_CATALOG_NAME, locale_dir)

    With this code, sphinx searches a message catalog from
    ``${package_dir}/locales/${language}/LC_MESSAGES/myextension.mo``.
    The :confval:`language` is used for the searching.

    .. versionadded:: 1.8
    r   r   r   c                   s*   t  st | S t }|| S r   )rn   r
   rm   r   )r   r[   rl   r   r   r      s   


z get_translation.<locals>.gettextN)r   r   r   r   r   )rU   r   r   r   rl   r   get_translation   s   rp   rb   	AttentionCautionDangerErrorHint	ImportantNotezSee alsoTipWarning)
	attentioncautiondangererrorhint	importantnoteseealsotipwarning)rO   rP   )
rQ   rR   rS   rT   rU   r   r   r   r   rV   )NrO   )r`   rT   rU   r   r   rV   )rU   r   r   r   r   r   )rU   r   r   r   r   r@   )rP   )rU   r   r   r   r   ro   )rM   
__future__r   rf   rd   r   r   r   osr   typingr   collections.abcr   r   r	   r
   r   __annotations__r_   abspathdirname__file__rc   rk   rm   rn   rp   rj   __admonitionlabelsr   r   r   r   <module>   sL    Q+(

