Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
locale.cpython-313.pyc271 linesDownload Raw Back to __pycache__
1�

2��j�T��X�SrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJ	r	 SSK3Jr SSKJ
r
 SSKJrJrJrJrJr Sq0q\"[(/5qSqS	rS4\SS4S
jrS\SS4SjrSS\S\\SS4SjjrS\S\SS4SjrS\\4Sjr"SS5r "SS\ 5r!"SS\ 5r"g)a�Translation methods for generating localized strings.5 6To load a locale and generate a translated string::7 8    user_locale = tornado.locale.get("es_LA")9    print(user_locale.translate("Sign out"))10 11`tornado.locale.get()` returns the closest matching locale, not necessarily the12specific locale you requested. You can support pluralization with13additional arguments to `~Locale.translate()`, e.g.::14 15    people = [...]16    message = user_locale.translate(17        "%(list)s is online", "%(list)s are online", len(people))18    print(message % {"list": user_locale.list(people)})19 20The first string is chosen if ``len(people) == 1``, otherwise the second21string is chosen.22 23Applications should call one of `load_translations` (which uses a simple24CSV format) or `load_gettext_translations` (which uses the ``.mo`` format25supported by `gettext` and related tools).  If neither method is called,26the `Locale.translate` method will simply return the original string.27�N)�escape)�gen_log)�LOCALE_NAMES)�Iterable�Any�Union�Dict�Optional�en_USF��locale_codes�return�Localec�(�[R"U6$)a�Returns the closest match for the given locale codes.28 29We iterate over all given locale codes in order. If we have a tight30or a loose match for the code (e.g., "en" for "en_US"), we return31the locale. Otherwise we move to the next code in the list.32 33By default we return ``en_US`` if no translations are found for any of34the specified locales. You can change the default locale with35`set_default_locale()`.36)r�get_closest)r
s �TD:\code\apps\devtools\python\user_packages\Python313\site-packages\tornado/locale.py�getr>s�����|�,�,��codec�d�Uq[[[R	55[/-5qg)a#Sets the default locale.37 38The default locale is assumed to be the language used for all strings39in the system. The translations loaded from disk are mappings from40the default locale to the destination locale. Consequently, you don't41need to create a translation file for the default locale.42N)�_default_locale�	frozenset�list�
_translations�keys�_supported_locales)rs r�set_default_localerLs*���O�"�4�
�(:�(:�(<�#=��@Q�#Q�R�r�	directory�encodingc43�6�0q[R"U5GHnURS5(dMUR	S5up4[44R"SU5(d7[R"SU[RRX55 M�[RRX5nUcf[US5nUR[[R55nSSS5 W[R[R 4;aSnOSn[XQS	9n0[U'[#[$R&"U55H�up�U45(a[U465S47:aMU48Vs/sH'n[(R*"U5R-5PM) n49nU50SS51up�[U525S53:�aU54S55=(d SnOSnUS;a[R"S
UUU	S-5 M�U
[UR/U05U'M� SSS5 GM [1[3[R555[6/-5q[R:"S[=[855 g!,(df   GN�=fs snf!,(df   GM=f)uLoads translations from CSV files in a directory.56 57Translations are strings with optional Python-style named placeholders58(e.g., ``My name is %(name)s``) and their associated translations.59 60The directory should have translation files of the form ``LOCALE.csv``,61e.g. ``es_GT.csv``. The CSV files should have two or three columns: string,62translation, and an optional plural indicator. Plural indicators should63be one of "plural" or "singular". A given string can have both singular64and plural forms. For example ``%(name)s liked this`` may have a65different verb conjugation depending on whether %(name)s is one66name or a list of names. There should be two rows in the CSV file for67that string, one with plural indicator "singular", and one "plural".68For strings with no verbs that would change on translation, simply69use "unknown" or the empty string (or don't include the column at all).70 71The file is read using the `csv` module in the default "excel" dialect.72In this format there should not be spaces after the commas.73 74If no ``encoding`` parameter is given, the encoding will be75detected automatically (among UTF-8 and UTF-16) if the file76contains a byte-order marker (BOM), defaulting to UTF-8 if no BOM77is present.78 79Example translation ``es_LA.csv``::80 81    "I love you","Te amo"82    "%(name)s liked this","A %(name)s les gustó esto","plural"83    "%(name)s liked this","A %(name)s le gustó esto","singular"84 85.. versionchanged:: 4.386   Added ``encoding`` parameter. Added support for BOM-based encoding87   detection, UTF-16, and UTF-8-with-BOM.88z.csv�.z[a-z]+(_[A-Z]+)?$z!Unrecognized locale %r (path: %s)N�rbzutf-16z	utf-8-sig)r��unknown)�plural�singularr$z.Unrecognized plural indicator %r in %s line %d��Supported locales: %s)r�os�listdir�endswith�split�re�matchr�error�path�join�open�read�len�codecs�BOM_UTF16_LE�BOM_UTF16_BE�	enumerate�csv�readerr�89to_unicode�strip�90setdefaultrrrrr�debug�sorted)rrr0�locale�	extension�	full_path�bf�data�f�i�row�c�english�translationr%s               r�load_translationsrKZs��J�M��91�92�9�%���}�}�V�$�$�� �J�J�s�O����x�x�+�V�4�4��M�M�3�������Y�-�
�93
��G�G�L�L��1�	����i��&�"��w�w�s�6�#6�#6�7�8��'���+�+�V�-@�-@�A�A�#��94'���)�
/�1�$&�M�&�!�#�C�J�J�q�M�2����c�#�h��l��=@�A�S��v�(�(��+�1�1�3�S��A�'*�2�A�w�$���s�8�a�<� ��V�0�y�F�&�F��!B�B��M�M�H����A��	��HS�
�f�%�0�0���<�W�E�#3�0�
/�3&�Z#�4�
�(:�(:�(<�#=��@Q�#Q�R���M�M�)�6�2D�+E�F�A'�&�� B�0�
/�s,�	)I1�,A95J�6.J96�$A-J�197J	�J�98J	�domainc	��0q[R"[RR	USSUS-55Hzn[RR[RR
[RR
U555n[R"XU/S9[U'M| [[[R55[ /-5qSq[R&"S[)["55 g![a-n[R"SU[U55 SnAGMSnAff=f)	a�Loads translations from `gettext`'s locale tree99 100Locale tree is similar to system's ``/usr/share/locale``, like::101 102    {directory}/{lang}/LC_MESSAGES/{domain}.mo103 104Three steps are required to have your app translated:105 1061. Generate POT translation file::107 108    xgettext --language=Python --keyword=_:1,2 -d mydomain file1.py file2.html etc109 1102. Merge against existing POT file::111 112    msgmerge old.po mydomain.po > new.po113 1143. Compile::115 116    msgfmt mydomain.po -o {directory}/pt_BR/LC_MESSAGES/mydomain.mo117�*�LC_MESSAGESz.mo)�	languagesz$Cannot load translation for '%s': %sNTr()r�globr)r0r1�basename�dirname�gettextrJ�	Exceptionrr/�strrrrrr�_use_gettextr>r?)rrL�filename�lang�es     r�load_gettext_translationsr[�s���0�M��I�I�118�����Y��]�F�U�N�C����w�w��������������0I� J�K��	�")�"5�"5��d�V�#�M�$���#�4�
�(:�(:�(<�#=��@Q�#Q�R���L��M�M�)�6�2D�+E�F���	��M�M�@�$��A��O���	�s�D�119E�!E�Ec��[$)z1Returns a list of all the supported locale codes.)r�rr�get_supported_localesr^�s���rc
�l�\rSrSrSr0r\S\SS4Sj5r\S\SS4Sj5r	S\SS4S	jr120SS121\S\\S\\S\4S
jjr
SS\S122\S\\S\\S\4123SjjrSS\\\\R"4S\S\S\S\S\4SjjrSS\R"S\S\S\4SjjrS\S\4SjrS\S\4SjrSrg) r��z�Object representing a locale.124 125After calling one of `load_translations` or `load_gettext_translations`,126call `get` or `get_closest` to get a Locale object.127r
rc���UH�nU(dMURSS5nURS5n[U5S:�aM@[U5S:Xa*USR5S-USR	5-nU[128;aUR
U5s $USR5[129;dM�UR
USR55s $ UR
[5$)z4Returns the closest match for the given locale code.�-�_r#rr')�replacer,r4�lower�upperrrr)�clsr
r�partss    rr�Locale.get_closest�s���!�D����<�<��S�)�D��J�J�s�O�E��5�z�A�~���U��q���Q�x�~�~�'�#�-��a����0@�@���)�)��w�w�t�}�$��Q�x�~�~��#5�5��w�w�u�Q�x�~�~�/�0�0�!��w�w��'�'rrc��XR;abU[;de[RUS5nUc
[	U05nO"[130(a[
X5nO[	X5nX0RU'URU$)z^Returns the Locale for the given locale code.131 132If it is not supported, we raise an exception.133N)�_cacherrr�	CSVLocalerW�
GettextLocale)rgr�translationsr@s    rr�134Locale.get�su���z�z�!��-�-�-�-�(�,�,�T�4�8�L��#�"�4��,����&�t�:��"�4�6��%�J�J�t���z�z�$��rNc��Xl[R"U05RSS5UlSUlSH,nURRU5(dM%SUl O URnU"S5U"S5U"S5U"S	5U"S1355U"S5U"S5U"S
5U"S5U"S5U"S5U"S5/UlU"S5U"S5U"S5U"S5U"S5U"S5U"S5/Ulg)N�name�UnknownF)�fa�ar�heT�January�February�March�April�May�June�July�August�	September�October�November�December�Monday�Tuesday�	Wednesday�Thursday�Friday�Saturday�Sunday)	rrrrq�rtl�136startswith�	translate�_months�	_weekdays)�selfr�prefixrcs    r�__init__�Locale.__init__
s����	� �$�$�T�2�.�2�2�6�9�E��	����(�F��y�y�#�#�F�+�+�����)�
�N�N��
�i�L�
�j�M�
�g�J�
�g�J�
�e�H�
�f�I�
�f�I�
�h�K�
�k�N�
�i�L�
�j�M�
�j�M�
137���
�h�K�
�i�L�
�k�N�
�j�M�
�h�K�
�j�M�
�h�K�138��r�message�plural_message�countc��[5e)z�Returns the translation for the given message for this locale.139 140If ``plural_message`` is given, you must also provide141``count``. We return ``plural_message`` when ``count != 1``,142and we return the singular form for the given message when143``count == 1``.144��NotImplementedError�r�r�r�r�s    rr��Locale.translate0s
��"�#�#r�contextc��[5e�Nr��r�r�r�r�r�s     r�pgettext�Locale.pgettext?s
��"�#�#r�date�145gmt_offset�relative�shorter�full_formatc���[U[[45(a8[RR	U[R146R5nURc'UR[R147RS9n[RR[R148R5nX:�aU(aX-149RS:aUnOSnU[R"US9-150nU[R"US9-151nU[R"SS9-152n	Xa-153n154U155RnU156RnURn
SnU(d�U(a[US:XaUUS	:aU
"S157SU5SU0-$US
:a[US-5nU
"SSU5SU0-$[US-5nU
"SSU5SU0-$US:Xa	U
"S5nOzUS:Xa9URU	R:XaU(aU(aU
"S5OU
"S5nO;US:aU(aU
"S5OU
"S5nOUS:aU(aU
"S5OU
"S5nUcU(aU
"S 5OU
"S!5nUR S";nU(aS#UR"UR$4-nO�UR S$:Xa9S%S&UR"S':�UR"S'-=(d S'UR$4-nO8S(UR"S'-=(d S'UR$S)UR"S':�4-nUUR&UR(S-158UR*UR-5[/UR5[/UR05US*.-$)+a�Formats the given date.159 160By default, we return a relative time (e.g., "2 minutes ago"). You161can return an absolute date string with ``relative=False``.162 163You can force a full format date ("July 10, 1980") with164``full_format=True``.165 166This method is primarily intended for dates in the past.167For dates in the future, we fall back to full format.168 169.. versionchanged:: 6.4170   Aware `datetime.datetime` objects are now supported (naive171   datetimes are still assumed to be UTC).172N)�tzinfo�<T��minutes�)�hoursr�2z1 second agoz%(seconds)d seconds ago�secondsi�gN@z1 minute agoz%(minutes)d minutes agor�g �@z1731 hour agoz%(hours)d hours agor�z%(time)sr'�	yesterdayzyesterday at %(time)s�z%(weekday)sz%(weekday)s at %(time)siN�%(month_name)s %(day)sz"%(month_name)s %(day)s at %(time)sz %(month_name)s %(day)s, %(year)sz,%(month_name)s %(day)s, %(year)s at %(time)s)�enr�zh_CNz%d:%02dr�z	%s%d:%02d)u上午u下午�z174%d:%02d %s)�am�pm)�175month_name�weekday�day�year�time)�176isinstance�int�float�datetime�
fromtimestamp�timezone�utcr�rd�nowr��	timedelta�daysr��roundr�r�hour�minuter��monthr�r�rVr�)r�r�r�r�r�r�r��177local_date�	local_now�local_yesterday�178differencer�r�rc�formatr�r��tfhour_clock�str_times                   r�format_date�Locale.format_dateHsU��.�d�S�%�L�)�)��$�$�2�2�4��9J�9J�9N�9N�O�D��;�;���<�<�x�'8�'8�'<�'<�<�=�D����#�#�H�$5�$5�$9�$9�:���:��T�Z�0�0�2�5���#���H�.�.�z�B�B�179��(�,�,�Z�@�@�	�#�h�&8�&8�r�&B�B���Z�180��$�$�������N�N������D�A�I��R�<��^�-F��P�!�7�T����W�$�#�G�d�N�3�G��^�-F��P�!�7�T����g��3�4����'<�e�D��QV�GW�W�W��q�y��:������z�~�~��1D�1D�D��+2��;���:Q�8R�����-4��=�)�!�<U�:V�������.�/��?�@���>���4�5��E�F�
��y�y�(@�@��� �J�O�O�Z�5F�5F�#G�G�H�
�Y�Y�'�
!�"�0����B�1F�G����"�$�*���!�!�&��H�$����"�$�*���!�!��Z�_�_��2�3�'��H���,�,�z�'7�'7�!�';�<��~�~�j�&8�&8�&:�;��z�~�~�&��181���(��182�183�	184r�dowc�z�U[R"US9-185nURnU(aWU"S5URURS-186UR187UR
5[UR5S.-$U"S5URURS-188[UR5S.-$)z|Formats the given date as a day of week.189 190Example: "Monday, January 22". You can remove the day of week with191``dow=False``.192r�z#%(weekday)s, %(month_name)s %(day)sr')r�r�r�r�)r�r�)	r�r�r�r�r�r�r�rVr�)r�r�r�r�r�rcs      r�193format_day�Locale.format_day�s����H�.�.�z�B�B�194��N�N����:�;�"�l�l�:�+;�+;�a�+?�@��>�>�*�*<�*<�*>�?��:�>�>�*�?��
��-�.�"�l�l�:�+;�+;�a�+?�@��:�>�>�*�2��
rrhc��URn[U5S:Xag[U5S:XaUS$URRS5(aSOSnU"S5UR	USS	5U[U5S-195S196.-$)z�Returns a comma-separated list for the given list of parts.197 198The format is, e.g., "A, B and C", "A and B" or just "A" for lists199of size 1.200r�r'rsu و z, z%(commas)s and %(last)sN�����)�commas�last)r�r4rr�r1)r�rhrc�commas    rr�Locale.list�s���
�N�N���u�:��?���u�:��?���8�O�"�i�i�2�2�4�8�8�201�d���*�+��j�j��s���,��#�e�*�q�.�)�/202�203�	204r�valuec���URS;a[U5$[U5n/nU(a"URUSS5 USSnU(aM"SR[	U55$)z7Returns a comma-separated number for the given integer.)r�r�����N�,)rrV�appendr1�reversed)r�r��srhs    r�friendly_number�Locale.friendly_number�sb���9�9�O�+��u�:����J������L�L��2�3�� ��#�2��A��a��x�x����(�(r)r�r�rrqr��NN)rTFF)rT)�__name__�205__module__�__qualname__�__firstlineno__�__doc__rk�classmethodrVrrr�r206r�r�r�rr�r��boolr�r�rrr��__static_attributes__r]rrrr�s�����F��(��(��(��(�"� �s� �x� �� �"!207�S�!208�T�!209�L)-�#�	
$��
$�!��
�
$���}�	
$�210211
�
$�&)-�#�$��$��$�!��
�	$�212��}�$�213
�
$����!�
h214��C��� 1� 1�1�2�h215��h216��	h217�218�h219��
h220�221
�h222�VIM���%�%��36��AE��	
��,223�#�224�#�225�"	)�S�	)�S�	)rc�^�\rSrSrSrS\S\\\\\44SS4U4SjjrSS\S	\\S226\\	S\4Sjjr227SS\S\S	\\S228\\	S\4229S
jjrSrU=r
$)rli�z=Locale implementation using tornado's CSV translation format.rrnrNc�0>�X l[TU]	U5 gr�)rn�superr��r�rrn�	__class__s   �rr��CSVLocale.__init__�s���(��
����rr�r�r�c���UbGUceUS:waUnURRS05nO9URRS05nOURRS05nURX5$)Nr'r%r&r$)rnr)r�r�r�r��message_dicts     rr��CSVLocale.translate�s{���%��$�$�$���z�(��#�0�0�4�4�X�r�B��#�0�0�4�4�Z��D���,�,�0�0��B�?�L�����1�1rr�c�t�UR(a[R"S5 URX#U5$)Nz&pgettext is not supported by CSVLocale)rnr�warningr�r�s     rr��CSVLocale.pgettext�s+������O�O�D�E��~�~�g�u�=�=r)rnr�)r�r�r�r�r�rVr	r�r230r�r�r�r��
__classcell__�r�s@rrlrl�s����G��S���S�$�s�C�x�.�5H�0I��d��)-�#�	2��2�!��
�2���}�	2�231232
�2�*)-�#�	>��	>��	>�!��
�		>�233��}�	>�234
�
	>�	>rrlc�^�\rSrSrSrS\S\RSS4U4SjjrSS\S	\	\S235\	\236S\4SjjrSS\S\S	\	\S237\	\238S\4239S
jjrSr
U=r$)rmi	z1Locale implementation using the `gettext` module.rrnrNc�h>�URUlURUl[TU]
U5 gr�)�ngettextrTr�r�r�s   �rr��GettextLocale.__init__s,���$�-�-��
�#�+�+���	����rr�r�r�c�X�UbUceURXU5$URU5$r�)r�rTr�s    rr��GettextLocale.translates6���%��$�$�$��=�=��%�@�@��<�<��(�(rr�c���UbKUceU[U3U[U3U4nUR"U6n[U;aURX#U5nU$U[U3nURU5n[U;aUnU$)a�Allows to set context for translation, accepts plural forms.240 241Usage example::242 243    pgettext("law", "right")244    pgettext("good", "right")245 246Plural message example::247 248    pgettext("organization", "club", "clubs", len(clubs))249    pgettext("stick", "club", "clubs", len(clubs))250 251To generate POT file with context, add following options to step 1252of `load_gettext_translations` sequence::253 254    xgettext [basic options] --keyword=pgettext:1c,2 --keyword=pgettext:1c,2,3255 256.. versionadded:: 4.2257)�CONTEXT_SEPARATORr�rT)r�r�r�r�r��msgs_with_ctxt�result�
msg_with_ctxts        rr��GettextLocale.pgettexts���4�%��$�$�$��)�-�.�w�i�8��)�-�.�~�.>�?���N�258�]�]�N�3�F� �F�*����w��F���M�&�i�(9�':�7�)�D�M��\�\�-�0�F� �F�*� ���Mr)rTr�r�)r�r�r�r�r�rVrT�NullTranslationsr�r259r�r�r�r�r�r�s@rrmrm	s����;��S���0H�0H��T��)-�#�	260)��261)�!��
�262)���}�	263)�264265
�266)� )-�#�,��,��,�!��
�	,�267��}�,�268
�
,�,rrmr�)#r�r5r9r�rTrQr)r-�tornador�tornado.logr�tornado._locale_datar�typingrrrr	r269rrrrrWrrVrrrKr[r^rrlrmr]rr�<module>rs����2�270����	�	���-�7�7����
���0�1������-�s�-�x�-�S�S�S�T�S�TG��TG���
�TG��TG�n'G��'G�c�'G�d�'G�T�x��}��271B)�B)�J!>��!>�HB�F�Br
codekingpro/portable-devtools · Team Ai