o $a" @sUdZddlZddlZddlmZmZddlmZddlmZm Z m Z m Z m Z m Z mZmZGdddeZeeae eeefefed< d0d e e ed e ed ededeeeff ddZd1dedeee efddfddZded edeeeffddZd0d ededefddZd0d ededefddZd edededefddZd2d edede fd d!Zed Zed d"Zed#ed$ed%ed&ed'ed(ed)ed*ed+ed,d- ZiZ e eefed.<iZ!e eefed/<dS)3z sphinx.locale ~~~~~~~~~~~~~ Locale utilities. :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. N) UserString defaultdict)NullTranslations)AnyCallableDictIterableListOptionalTupleUnionc@sneZdZdZdZdededefddZde efdd Z dededd fd d Z e defd dZ d1dededefddZdeefddZdefddZdedefddZdedefddZdedefddZdedefddZdedefd d!Zdedefd"d#Zd$edefd%d&Zde ee ed'fffd(d)Zd*e ee efdd fd+d,Zd2d-d.Zdefd/d0Zd S)3_TranslationProxya Class for proxy strings from gettext translations. This is a helper for the lazy_* functions from this module. The proxy implementation attempts to be as complete as possible, so that the lazy objects should mostly work as expected, for example for sorting. This inherits from UserString because some docutils versions use UserString for their Text nodes, which then checks its argument for being either a basestring or UserString, otherwise calls str() -- not unicode() -- on it. _func_argsfuncargsreturncGs|st|St|SN)strobject__new__)clsrrr8/usr/lib/python3/dist-packages/sphinx/locale/__init__.pyr s z_TranslationProxy.__new__cCs|jf|jSrrselfrrr__getnewargs__&sz _TranslationProxy.__getnewargs__NcGs||_||_dSrr)rrrrrr__init__)s z_TranslationProxy.__init__cCs |j|jSrrrrrrdata-s z_TranslationProxy.dataencodingerrorscCs,|r|r |j||S|j|S|jSr)rencode)rr r!rrrr"4s   z_TranslationProxy.encodecCsttSr)dirrrrrr__dir__=sz_TranslationProxy.__dir__cCs t|jSr)rrrrrr__str__@ z_TranslationProxy.__str__othercCs |j|Srrrr'rrr__add__Cr&z_TranslationProxy.__add__cCs ||jSrr(r)rrr__radd__Fr&z_TranslationProxy.__radd__cCs |j|Srr(r)rrr__mod__Ir&z_TranslationProxy.__mod__cCs ||jSrr(r)rrr__rmod__Lr&z_TranslationProxy.__rmod__cCs |j|Srr(r)rrr__mul__Or&z_TranslationProxy.__mul__cCs ||jSrr(r)rrr__rmul__Rr&z_TranslationProxy.__rmul__namecCs|dkr|St|j|S)N __members__)r$getattrr)rr0rrr __getattr__Us z_TranslationProxy.__getattr__.cCs |j|jfSrrrrrr __getstate__Z z_TranslationProxy.__getstate__tupcCs|\|_|_dSrr)rr6rrr __setstate__]sz_TranslationProxy.__setstate__cCs|Srrrrrr__copy__`sz_TranslationProxy.__copy__cCs4z dtt|jWStyd|jjYSw)Niz <%s broken>)reprrr Exception __class____name__rrrr__repr__cs  z_TranslationProxy.__repr__)NN)rr )r= __module__ __qualname____doc__ __slots__rrrrr rrpropertyrbytesr"r r$r%r*r+r,r-rr.r/r3r4r7r8r>rrrrr s,   r translatorssphinxgeneral locale_dirslanguagecatalog namespacerc Cst||f}|jturd}d}|r d|vr ||ddg}n|r&|g}nd}|D]!}ztj|||d}|dur<|}n||Wq*tyKYq*w|durUt}d}|t||f<||fS)aLook 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). NT_r) localedir languagesF) rEgetr<rsplitgettext translation add_fallbackr;) rHrIrJrK translatorhas_translationrNdir_transrrrinitms0     rXcategoryvaluecCs*z t||WdStjyYdSw)aUpdate locale settings. This does not throw any exception even if update fails. This is workaround for Python's bug. For more details: * https://github.com/sphinx-doc/sphinx/issues/5724 * https://bugs.python.org/issue18378#msg215215 .. note:: Only for internal use. Please don't call this method from extensions. This will be removed in future. N)locale setlocaleError)rYrZrrrr\s r\ locale_dircCs<z ttj\}}Wn tyd}Ynwt|g||dS)z>Initialize locale for console. .. versionadded:: 1.8 Nconsole)r[ getlocale LC_MESSAGESAttributeErrorrX)r^rJrIrLrrr init_consoles  rccCs t||fSrrErJrKrrrget_translatorr5rfcCs ||ftvSrrdrerrris_translator_registeredr5rgmessagecCst||}||S)zcUsed instead of _ when creating TranslationProxy, because _ is not bound yet at that time. )rfrQ)rJrKrhrTrrr_lazy_translates  rics dtdtdtffdd }|S)aAGet 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 rhrrcsNts tt|St}t|dkr||S|||d|dS)Nr)rgr rirflenrQngettext)rhrrTrerrrQs    z get_translation..gettext)rr)rJrKrQrrerget_translations rmr_ AttentionCautionDangerr]Hint ImportantNotezSee alsoTipWarning) attentioncautiondangererrorhint importantnoteseealsotipwarning versionlabelspairindextypes)rFrGr)rG)"rArQr[ collectionsrrrtypingrrrrr r r r r rEr__annotations__boolrXintr\rcrfrgrirmrL__admonitionlabelsrrrrrrsJ  ( X  $**