U
    \Sh                     @  s8  U d Z ddlmZ ddlZddlmZmZ ddlmZ ddl	m
Z
mZmZ G dd dZi Zd	ed
< d-ddddddddZeeeZedfddddddZd.ddddddZd/ddddddZd0ddddd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d+d,
ZdS )1zLocale utilities.    )annotationsN)NullTranslationstranslation)path)AnyCallableIterablec                   @  s  e Zd ZdZdZdddddddZddd	d
ZddddZdddddZddddZ	dddddZ
d dddZddddZdddddZddddd Zdddd!d"Zdddd#d$Zdddd%d&Zdddd'd(Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5S )6_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strNone)	catalogue	namespacemessagereturnc                 C  s   || _ || _|| _d S Nr
   )selfr   r   r    r   I/root/rtd-docs/venv/lib/python3.8/site-packages/sphinx/locale/__init__.py__init__   s    z_TranslationProxy.__init__)r   c                 C  s:   zt | j| jf | jW S  tk
r4   | j Y S X d S r   )translatorsr   r   gettextr   KeyErrorr   r   r   r   __str__   s    z_TranslationProxy.__str__z	list[str]c                 C  s   t tS r   )dirr   r   r   r   r   __dir__   s    z_TranslationProxy.__dir__r   )namer   c                 C  s   t |  |S r   )getattrr   )r   r    r   r   r   __getattr__!   s    z_TranslationProxy.__getattr__ztuple[str, str, str]c                 C  s   | j | j| jfS r   r
   r   r   r   r   __getstate__$   s    z_TranslationProxy.__getstate__)tupr   c                 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__*   s    z_TranslationProxy.__copy__c                 C  sP   zd|   W S  tk
rJ   | jjd| j d| j d| j d  Y S X d S )Ni(z, ))r   	Exception	__class____name__r   r   r   r   r   r   r   __repr__-   s    z_TranslationProxy.__repr__)otherr   c                 C  s   |   | S r   r   r   r.   r   r   r   __add__4   s    z_TranslationProxy.__add__c                 C  s   ||    S r   r/   r0   r   r   r   __radd__7   s    z_TranslationProxy.__radd__c                 C  s   |   | S r   r/   r0   r   r   r   __mod__:   s    z_TranslationProxy.__mod__c                 C  s   ||    S r   r/   r0   r   r   r   __rmod__=   s    z_TranslationProxy.__rmod__c                 C  s   |   | S r   r/   r0   r   r   r   __mul__@   s    z_TranslationProxy.__mul__c                 C  s   ||    S r   r/   r0   r   r   r   __rmul__C   s    z_TranslationProxy.__rmul__c                 C  s   t |  S r   )hashr   r   r   r   r   __hash__F   s    z_TranslationProxy.__hash__c                 C  s   |   |kS r   r/   r0   r   r   r   __eq__I   s    z_TranslationProxy.__eq__c                 C  s   |   |k S r   r/   )r   stringr   r   r   __lt__L   s    z_TranslationProxy.__lt__c                 C  s   ||   kS r   r/   )r   charr   r   r   __contains__O   s    z_TranslationProxy.__contains__c                 C  s   t |  S r   )lenr   r   r   r   r   __len__R   s    z_TranslationProxy.__len__c                 C  s   |   | S r   r/   )r   indexr   r   r   __getitem__U   s    z_TranslationProxy.__getitem__N)r,   
__module____qualname____doc__	__slots__r   r   r   r"   r#   r%   r&   r-   r1   r2   r3   r4   r5   r6   r8   r9   r;   r=   r?   rA   r   r   r   r   r	      s,   r	   z'dict[tuple[str, str], NullTranslations]r   sphinxgeneralzIterable[str | None]z
str | Noner   ztuple[NullTranslations, bool])locale_dirslanguagecatalogr   r   c           	   	   C  s   t ||f}|jtkrd}|rDd|kr<||dd g}qH|g}nd}| D ]D}z*t|||d}|dkrn|}n
|| W qL tk
r   Y qLX qL|dk	rd}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_r   )	localedir	languagesTF)r   getr+   r   splitr   add_fallbackr*   )	rH   rI   rJ   r   
translatorrM   Zdir_ZtransZhas_translationr   r   r   init\   s,    
rR   )
locale_dirrJ   r   c                 C  s>   zt t j\}}W n tk
r,   d}Y nX t| g||dS )z>Initialize locale for console.

    .. versionadded:: 1.8
    Nconsole)locale	getlocaleLC_MESSAGESAttributeErrorrR   )rS   rJ   rI   rK   r   r   r   init_console   s
    
rY   r   )rJ   r   r   c                 C  s   t || ft S r   )r   rN   r   rJ   r   r   r   r   get_translator   s    r[   boolc                 C  s   || ft kS r   )r   rZ   r   r   r   is_translator_registered   s    r]   zCallable[[str], str]c                   s   dd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 d S r   )r]   r	   r[   r   )r   rQ   rZ   r   r   r      s    

z get_translation.<locals>.gettextr   )rJ   r   r   r   rZ   r   get_translation   s    r^   rT   Z	AttentionZCautionZDangerErrorZHintZ	ImportantZNotezSee alsoZTipWarning)
Z	attentionZcautionZdangererrorhintZ	importantZnoteZseealsoZtipwarning)rF   rG   )rF   rG   )rF   rG   )rG   )rD   
__future__r   rU   r   r   r   osr   typingr   r   r   r	   r   __annotations__rR   abspathdirname__file__Z_LOCALE_DIRrY   r[   r]   r^   rK   __Zadmonitionlabelsr   r   r   r   <module>   s<   N  /'
