W^-dZddlZddlZddlmZmZddlmZddl m Z da ia e tgadadZd Zd ZGd d eZed krddlZejdSdS)aO Internationalisation using Babel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The locale support of tornado as such is pretty basic and does not offer support for merging translation catalogs and several other features most multi language applications require. This module tries to retain the same API as that of tornado.locale while implement the required features with the support of babel. .. note:: CSV Translations are not supported :copyright: (c) 2012 by Openlabs Technologies & Consulting (P) Limited :copyright: (c) 2009 by Facebook (Tornado Project) :license: BSD, see LICENSE for more details. :changes: 12/11/23 - E. PASCUAL (Centre Scientifique et Technique du Batiment): fixed implementation of translations merge process in load_gettext_translations N) TranslationsNullTranslations)Locale)datesen_USFctj|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() below. )r get_closest) locale_codess t/builddir/build/BUILD/imunify360-venv-2.6.2/opt/imunify360/venv/lib/python3.11/site-packages/aiohttp_babel/locale.pygetr &s  | ,,c|attttgzadS)aUSets the default locale, used in get_closest_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)codes r set_default_localer4s>O" ]   ! !""o%6688r c tj|D]}|drtjtj||rV t j||g|}|tvr!t| |n |t|<#t$r-}tj d|t|Yd}~d}~wwxYwtttt"gzadatjdt+t$dS)z-Loads translations from gettext's locale tree.z$Cannot load translation for '%s': %sNTzSupported locales: %s)oslistdir startswithpathisfilejoinrloadrmerge Exceptionloggingerrorstrrrrrr _use_gettextinfosorted) directorydomainlang translationes r load_gettext_translationsr-CsG  9%% ??3     7>>"',,y$77 8 8   &+IvvFFK}$$d#))+6666&1 d#    M@$A O O O HHHH # ]   ! !""o%6688L L(&1C*D*DEEEEEs,A B88 C/#C**C/cjeZdZdZedZedZd dZddZddZ dd Z dd Z dS)rzObject representing a locale. After calling one of `load_translations` or `load_gettext_translations`, call `get` or `get_closest` to get a Locale object. c>|D]}|s|dd}|d}t|dkrEt|dkr8|ddz|dz}|t vr||cS|dt vr/||dcS|tS)z4Returns the closest match for the given locale code.-_r)replacesplitlenlowerupperrr r)clsr rpartss r r zLocale.get_closestds! 1 1D <<S))DJJsOOE5zzA~~UqQx~~''#-a0@0@@)))wwt}}$$$Qx~~#555wwuQx~~//000006ww'''r c t|dsi|_||jvrX|tvsJt|t }||}||_||j|<|j|S)znReturns the Locale for the given locale code. If it is not supported, we raise an exception. _cache)hasattrr<rrr rparse translations)r9rr?locales r r z Locale.getvs sH%% CJ sz ! !-----(,,T3C3E3EFFLYYt__F".F %CJt z$r Nc |!|J|j|||}n|j|}t|r |jdi|n|S)a` Translates message and returns new message as str :param str message: original message :param str plural_message: plural format of the message :param int count: number proper plural message for generation :param kwargs: named placeholders for message templating :return str: translated message N)r? ungettextugettextr6format)selfmessageplural_messagecountkwargss r translatezLocale.translatesw  %$$$'1100GG'0099G+.v;;C~w~'''''GCr mediumc0tj||||S)ar Return a date formatted according to the given pattern. :param datetime: the datetime object; if None, the current date and time is used :param format: one of "full", "long", "medium", or "short", or a custom date/time pattern :param tzinfo: the timezone to apply to the time for display >>> from datetime import datetime >>> locale = Locale.parse('pt_BR') >>> locale >>> dt = datetime(2007, 04, 01, 15, 30) >>> locale.format_datetime(dt) u'01/04/2007 15:30:00' )rformat_datetime)rFdatetimerEtzinfos r rNzLocale.format_datetimes$$XvvtDDDr c.tj|||S)a% Return a date formatted according to the locale. :param date: the date or datetime object; if None, the current date is used :param format: one of "full", "long", "medium", or "short", or a custom date/time pattern )r format_date)rFdaterEs r rRzLocale.format_dates vt444r c0tj||||S)ar Return a time formatted according to the locale. :param time: the time or datetime object; if None, the current time in UTC is used :param format: one of "full", "long", "medium", or "short", or a custom date/time pattern :param tzinfo: the time-zone to apply to the time for display )r format_time)rFtimerErPs r rUzLocale.format_times vvt<<rjs . 88888888000000 Y011  - - - 8 8 8FFF4uKuKuKuKuK_uKuKuKp zNNNGOr