K iRLdZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZmZmZmZmZdaiaet(gadad Zd ed d fd Zded dfdZddedeed dfdZdeded dfdZd eefdZGdd Z Gdde Z!Gdde Z"y)aTranslation methods for generating localized strings. To load a locale and generate a translated string:: user_locale = tornado.locale.get("es_LA") print(user_locale.translate("Sign out")) `tornado.locale.get()` returns the closest matching locale, not necessarily the specific locale you requested. You can support pluralization with additional arguments to `~Locale.translate()`, e.g.:: people = [...] message = user_locale.translate( "%(list)s is online", "%(list)s are online", len(people)) print(message % {"list": user_locale.list(people)}) The first string is chosen if ``len(people) == 1``, otherwise the second string is chosen. Applications should call one of `load_translations` (which uses a simple CSV format) or `load_gettext_translations` (which uses the ``.mo`` format supported by `gettext` and related tools). If neither method is called, the `Locale.translate` method will simply return the original string. N)escape)gen_log) LOCALE_NAMES)IterableAnyUnionDictOptionalen_USF locale_codesreturnLocalec&tj|S)aReturns the closest match for the given locale codes. We iterate over all given locale codes in order. If we have a tight or a loose match for the code (e.g., "en" for "en_US"), we return the locale. Otherwise we move to the next code in the list. By default we return ``en_US`` if no translations are found for any of the specified locales. You can change the default locale with `set_default_locale()`. )r get_closest)r s T/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/tornado/locale.pygetr>s   | ,,codecd|atttj tgzay)a7Sets the default locale. The default locale is assumed to be the language used for all strings in the system. The translations loaded from disk are mappings from the default locale to the destination locale. Consequently, you don't need to create a translation file for the default locale. N)_default_locale frozensetlist _translationskeys_supported_locales)rs rset_default_localerLs*O"4 (:(:(<#=@Q#QRr directoryencodingc iatj|D]}|jds|j d\}}t j d|s6tjd|tjj||vtjj||}|dt|d5}|jttj}dddtjtj fvrd}nd}t|| 5}it|<t#t%j&|D]\} } | rt| d kr| D cgc]%} t)j*| j-'} } | dd \} } t| d kDr | d xsd }nd }|d vrtjd ||| dz| t|j/|i| < dddt1t3tj5t6gzatj:dt=t8y#1swYkxYwcc} w#1swYRxYw)uwLoads translations from CSV files in a directory. Translations are strings with optional Python-style named placeholders (e.g., ``My name is %(name)s``) and their associated translations. The directory should have translation files of the form ``LOCALE.csv``, e.g. ``es_GT.csv``. The CSV files should have two or three columns: string, translation, and an optional plural indicator. Plural indicators should be one of "plural" or "singular". A given string can have both singular and plural forms. For example ``%(name)s liked this`` may have a different verb conjugation depending on whether %(name)s is one name or a list of names. There should be two rows in the CSV file for that string, one with plural indicator "singular", and one "plural". For strings with no verbs that would change on translation, simply use "unknown" or the empty string (or don't include the column at all). The file is read using the `csv` module in the default "excel" dialect. In this format there should not be spaces after the commas. If no ``encoding`` parameter is given, the encoding will be detected automatically (among UTF-8 and UTF-16) if the file contains a byte-order marker (BOM), defaulting to UTF-8 if no BOM is present. Example translation ``es_LA.csv``:: "I love you","Te amo" "%(name)s liked this","A %(name)s les gustó esto","plural" "%(name)s liked this","A %(name)s le gustó esto","singular" .. versionchanged:: 4.3 Added ``encoding`` parameter. Added support for BOM-based encoding detection, UTF-16, and UTF-8-with-BOM. z.csv.z[a-z]+(_[A-Z]+)?$z!Unrecognized locale %r (path: %s)Nrbzutf-16z utf-8-sig)runknown)pluralsingularr$z.Unrecognized plural indicator %r in %s line %dSupported locales: %s)roslistdirendswithsplitrematchrerrorpathjoinopenreadlencodecs BOM_UTF16_LE BOM_UTF16_BE enumeratecsvreaderr to_unicodestrip setdefaultrrrrrdebugsorted)rrr0locale extension full_pathbfdatafirowcenglish translationr%s rload_translationsrKZs9JM 9%,T}}V$  JJsO xx+V4 MM3 Y-  GGLLD1  i& 9"wws6#6#678 9++V-@-@AA# ')h / T1$&M& !#CJJqM2 T3c#hl=@Av((+113AA'*2Aw$s8a< V0yF&F!BBMMHA  HS f%00 new.po 3. Compile:: msgfmt mydomain.po -o {directory}/pt_BR/LC_MESSAGES/mydomain.mo * LC_MESSAGESz.mo) languagesz$Cannot load translation for '%s': %sNTr()rglobr)r0r1basenamedirnamegettextrJ Exceptionrr/strrrrrr _use_gettextr>r?)rrLfilenamelanges rload_gettext_translationsr[s0MII  Y]FUNC ww0I JK ")"5"5 dV#M$  #4 (:(:(<#=@Q#QRL MM)62D+EF   MM@$A O  s D E D==EctS)z1Returns a list of all the supported locale codes.)rrrget_supported_localesr^s rc JeZdZdZiZededdfdZededdfdZdeddfdZ dd ed e ed e e defd Z dd ed ed e ed e e def dZ ddee eej fde dedededef dZ ddej de dedefdZdedefdZde defdZy)rzObject representing a locale. After calling one of `load_translations` or `load_gettext_translations`, call `get` or `get_closest` to get a Locale object. r rc|D]}|s|jdd}|jd}t|dkDr8t|dk(r*|djdz|dj z}|t vr|j |cS|djt vs|j |djcS|j tS)z4Returns the closest match for the given locale code.-_r#rr')replacer,r4lowerupperrrr)clsr rpartss rrzLocale.get_closests! 1D<<S)DJJsOE5zA~UqQx~~'#-a0@@))wwt}$Qx~~#55wwuQx~~/00 1ww''rrc||jvr]|tvsJtj|d}| t |i}nt r t ||}n t ||}||j|<|j|S)znReturns the Locale for the given locale code. If it is not supported, we raise an exception. N)_cacherrr CSVLocalerW GettextLocale)rfr translationsr@s rrz Locale.gets{ szz !-- --(,,T48L#"4,&t\:"46%CJJt zz$rNc ||_tj|ijdd|_d|_dD]&}|jj |sd|_n|j }|d|d|d|d |d |d |d |d |d|d|d|dg |_|d|d|d|d|d|d|dg|_y)NnameUnknownF)faarheTJanuaryFebruaryMarchAprilMayJuneJulyAugust SeptemberOctoberNovemberDecemberMondayTuesday WednesdayThursdayFridaySaturdaySunday) rrrrnrtl startswith translate_months _weekdays)selfrprefixrbs r__init__zLocale.__init__ s  $$T2.2269E ( Fyy##F+  NN iL jM gJ gJ eH fI fI hK kN iL jM jM    hK iL kN jM hK jM hK rmessageplural_messagecountct)a&Returns the translation for the given message for this locale. If ``plural_message`` is given, you must also provide ``count``. We return ``plural_message`` when ``count != 1``, and we return the singular form for the given message when ``count == 1``. NotImplementedErrorrrrrs rrzLocale.translate0s "##rcontextctNrrrrrrs rpgettextzLocale.pgettext?s "##rdate gmt_offsetrelativeshorter full_formatcpt|ttfr8tjj |tj j }|j*|jtj j }tjjtj j }||kDr|r||z jdkr|}nd}|tj|z }|tj|z }|tjdz } ||z } | j} | j} |j} d}|s|rX| dk(rS| d kr| d d | d | izS| d krt| dz }| dd|d|izSt| dz }| dd|d|izS| dk(r | d}nb| dk(r.|j| jk(r|r|r| dn| d}n/| dkr|r| dn| d}n| dkr|r| dn| d}||r| d n| d!}|j d"v}|rd#|j"|j$fz}nv|j d$k(r4d%d&|j"d'k\|j"d'zxsd'|j$fz}n3d(|j"d'zxsd'|j$d)|j"d'k\fz}||j&|j(dz |j*|j-t/|jt/|j0|d*zS)+a)Formats the given date. By default, we return a relative time (e.g., "2 minutes ago"). You can return an absolute date string with ``relative=False``. You can force a full format date ("July 10, 1980") with ``full_format=True``. This method is primarily intended for dates in the past. For dates in the future, we fall back to full format. .. versionchanged:: 6.4 Aware `datetime.datetime` objects are now supported (naive datetimes are still assumed to be UTC). N)tzinfo<Tminutes)hoursr2z 1 second agoz%(seconds)d seconds agosecondsi gN@z 1 minute agoz%(minutes)d minutes agorg @z 1 hour agoz%(hours)d hours agorz%(time)sr' yesterdayzyesterday at %(time)sz %(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:%02drz %s%d:%02d)u上午u下午 z %d:%02d %s)ampm) month_nameweekdaydayyeartime) isinstanceintfloatdatetime fromtimestamptimezoneutcrrcnowr timedeltadaysrroundrrhourminutermonthrrrVr)rrrrrrr local_date local_nowlocal_yesterday differencerrrbformatrr tfhour_clockstr_times r format_datezLocale.format_dateHsX. dS%L )$$2249J9J9N9NOD ;; <45EF  yy(@@  JOOZ5F5F#GGH YY' !"0B1FG"$*!!&H $"$*!!Z__23'H ,,z'7'7!';<~~j&8&8&:;z~~& (    rdowct|tj|z }|j}|rW|d|j|jdz |j |j t|jdzS|d|j|jdz t|jdzS)zFormats the given date as a day of week. Example: "Monday, January 22". You can remove the day of week with ``dow=False``. rz#%(weekday)s, %(month_name)s %(day)sr')rrrr)rr) rrrrrrrrVr)rrrrrrbs r format_dayzLocale.format_daysH..zBB NN :;"ll:+;+;a+?@>>**<*<*>?:>>*?  -."ll:+;+;a+?@:>>*2 rrgc|j}t|dk(ryt|dk(r|dS|jjdrdnd}|d|j |dd |t|dz d zS) zReturns a comma-separated list for the given list of parts. The format is, e.g., "A, B and C", "A and B" or just "A" for lists of size 1. rr'rpu و z, z%(commas)s and %(last)sN)commaslast)rr4rrr1)rrgrbcommas rrz Locale.lists NN u:? u:?8O"ii2248 d*+jjs,#e*q.)/   rvaluec|jdvr t|St|}g}|r|j|dd|dd}|rdjt |S)z7Returns a comma-separated number for the given integer.)rr N,)rrVappendr1reversed)rrsrgs rfriendly_numberzLocale.friendly_numbers` 99O +u:  J LL23 #2Axx((rNN)rTFF)rT)__name__ __module__ __qualname____doc__ri classmethodrVrrrr rrrrrrboolrrrrrr]rrrrs F((((" s x  "! S! T! L)-# $ $!  $} $ $&)-# $$$! $ } $ $! h C 1 112h h  h  h  h  h VIM%%36AE , # # " )S )S )rc eZdZdZdedeeeeeffddffd Z d dedeed eedefd Z d d ededeed eedef d Z xZ S)rjz=Locale implementation using tornado's CSV translation format.rrlrNc2||_t| |yr)rlsuperrrrrl __class__s rrzCSVLocale.__init__s( rrrrc|E|J|dk7r|}|jjdi}n9|jjdi}n|jjdi}|j||S)Nr'r%r&r$)rlr)rrrr message_dicts rrzCSVLocale.translates}  %$ $$z(#0044XrB #0044ZD ,,00B?L11rrcj|jrtjd|j|||S)Nz&pgettext is not supported by CSVLocale)rlrwarningrrs rrzCSVLocale.pgettexts-    OOD E~~g~u==rr) rrrrrVr rr rrr __classcell__rs@rrjrjsGSS$sCx.5H0Id)-# 22! 2} 2 2*)-# > > >! > } > >rrjc eZdZdZdedej ddffd Z d dedeed ee defd Z d d ededeed ee def d Z xZ S)rkz1Locale implementation using the `gettext` module.rrlrNch|j|_|j|_t| |yr)ngettextrTrrrs rrzGettextLocale.__init__ s,$-- #++  rrrrcV||J|j|||S|j|Sr)rrTrs rrzGettextLocale.translates8  %$ $$==.%@ @<<( (rrc|I|J|t||t||f}|j|}t|vr|j|||}|S|t|}|j|}t|vr|}|S)a?Allows to set context for translation, accepts plural forms. Usage example:: pgettext("law", "right") pgettext("good", "right") Plural message example:: pgettext("organization", "club", "clubs", len(clubs)) pgettext("stick", "club", "clubs", len(clubs)) To generate POT file with context, add following options to step 1 of `load_gettext_translations` sequence:: xgettext [basic options] --keyword=pgettext:1c,2 --keyword=pgettext:1c,2,3 .. versionadded:: 4.2 )CONTEXT_SEPARATORrrT)rrrrrmsgs_with_ctxtresult msg_with_ctxts rrzGettextLocale.pgettexts4  %$ $$)-.wi8)-.~.>?N #T]]N3F F*wFM&i(9':7)DM\\-0F F* Mrr) rrrrrVrTNullTranslationsrr rrrrrs@rrkrk s;S0H0HT)-# ) )!  )} ) ) )-# ,,,! , } , ,rrkr)#rr5r9rrTrQr)r-tornador tornado.logrtornado._locale_datartypingrrrr r rrrrrWrrVrrrKr[r^rrjrkr]rrrs2  -77 01  -s -x - SS ST STGTG TGTGn'G'Gc'Gd'GTx} B)B)J!>!>HBFBr