U
    ‰d  ã                   @  s$  U d Z ddlmZ ddlZddlZddlmZ ddddgZ	de 
¡ iZd	ed
< eƒ ZdddddœZddddœZddœdd„Zddœdd„Zd.ddddœdd„Zddœdd„Zdddœdd„Zddddœd d!„Zddd"dd#œd$d%„Zdddœd&d'„Zddd(d)œd*d+„Zddœd,d„Zddœd-d„ZdS )/z*Activate, get and deactivate translations.é    )ÚannotationsN)ÚlocalÚactivateÚ
deactivateÚdecimal_separatorÚthousands_separatorz1dict[str | None, gettext_module.NullTranslations]Ú_TRANSLATIONSÚ.ú )Úde_DEÚfr_FRÚit_ITÚpt_BRú,)r   r   r   z
str | None)Úreturnc                   C  sB   z&t d krW d S tj tj t ¡d¡W S  tk
r<   Y d S X d S )NÚlocale)Ú__file__ÚosÚpathÚjoinÚdirnameÚ	NameError© r   r   ú1/tmp/pip-unpacked-wheel-kd4adnh7/humanize/i18n.pyÚ_get_default_locale_path    s    r   zgettext_module.NullTranslationsc                	   C  s2   zt tj W S  ttfk
r,   t d   Y S X d S )N)r   Ú_CURRENTr   ÚAttributeErrorÚKeyErrorr   r   r   r   Úget_translation)   s    r   Ústr)r   r   r   c                 C  sP   |dkrt ƒ }|dkr"d}t|ƒ‚| tkrBt d|| g¡}|t| < | t_t|  S )aR  Activate internationalisation.

    Set `locale` as current locale. Search for locale in directory `path`.

    Args:
        locale (str): Language name, e.g. `en_GB`.
        path (str): Path to search for locales.

    Returns:
        dict: Translations.

    Raises:
        Exception: If humanize cannot find the locale folder.
    NznHumanize cannot determinate the default location of the 'locale' folder. You need to pass the path explicitly.Zhumanize)r   Ú	Exceptionr   Úgettext_moduleÚtranslationr   r   )r   r   Úmsgr"   r   r   r   r   0   s    ÿÚNonec                   C  s
   dt _dS )z Deactivate internationalisation.N)r   r   r   r   r   r   r   O   s    )Úmessager   c                 C  s   t ƒ  | ¡S )zvGet translation.

    Args:
        message (str): Text to translate.

    Returns:
        str: Translated text.
    )r   Úgettext©r%   r   r   r   Ú_gettextT   s    	r(   )Úmsgctxtr%   r   c                 C  sR   zt ƒ  | |¡W S  tk
rL   | d | }t ƒ  |¡}||krD|n| Y S X dS )a   Fetches a particular translation.

    It works with `msgctxt` .po modifiers and allows duplicate keys with different
    translations.

    Args:
        msgctxt (str): Context of the translation.
        message (str): Text to translate.

    Returns:
        str: Translated text.
    úN)r   Úpgettextr   r&   )r)   r%   Úkeyr"   r   r   r   Ú	_pgettext`   s    r-   Úint)r%   ÚpluralÚnumr   c                 C  s   t ƒ  | ||¡S )a6  Plural version of _gettext.

    Args:
        message (str): Singular text to translate.
        plural (str): Plural text to translate.
        num (int): The number (e.g. item count) to determine translation for the
            respective grammatical number.

    Returns:
        str: Translated text.
    )r   Úngettext)r%   r/   r0   r   r   r   Ú	_ngettexty   s    r2   c                 C  s   | S )aa  Mark a string as a translation string without translating it.

    Example usage:
    ```python
    CONSTANTS = [_gettext_noop('first'), _gettext_noop('second')]
    def num_name(n):
        return _gettext(CONSTANTS[n])
    ```

    Args:
        message (str): Text to translate in the future.

    Returns:
        str: Original text, unchanged.
    r   r'   r   r   r   Ú_gettext_noopˆ   s    r3   ztuple[str, str])Úsingularr/   r   c                 C  s   | |fS )aÊ  Mark two strings as pluralized translations without translating them.

    Example usage:
    ```python
    CONSTANTS = [ngettext_noop('first', 'firsts'), ngettext_noop('second', 'seconds')]
    def num_name(n):
        return _ngettext(*CONSTANTS[n])
    ```

    Args:
        singular (str): Singular text to translate in the future.
        plural (str): Plural text to translate in the future.

    Returns:
        tuple: Original text, unchanged.
    r   )r4   r/   r   r   r   Ú_ngettext_noop›   s    r5   c               	   C  s0   zt tj } W n ttfk
r*   d} Y nX | S )ztReturn the thousands separator for a locale, default to comma.

    Returns:
         str: Thousands separator.
    r   )Ú_THOUSANDS_SEPARATORr   r   r   r   ©Úsepr   r   r   r   ¯   s
    
c               	   C  s0   zt tj } W n ttfk
r*   d} Y nX | S )znReturn the decimal separator for a locale, default to dot.

    Returns:
         str: Decimal separator.
    r	   )Ú_DECIMAL_SEPARATORr   r   r   r   r7   r   r   r   r   ¼   s
    
)N)Ú__doc__Ú
__future__r   r&   r!   Úos.pathr   Ú	threadingr   Ú__all__ÚNullTranslationsr   Ú__annotations__r   r6   r9   r   r   r   r   r(   r-   r2   r3   r5   r   r   r   r   r   r   Ú<module>   s:    ÿü	ý	