Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../usr/lib64/python3....
File: gettext.py
[500] Fix | Delete
[501] Fix | Delete
# a mapping between absolute .mo file path and Translation object
[502] Fix | Delete
_translations = {}
[503] Fix | Delete
[504] Fix | Delete
def translation(domain, localedir=None, languages=None,
[505] Fix | Delete
class_=None, fallback=False, codeset=None):
[506] Fix | Delete
if class_ is None:
[507] Fix | Delete
class_ = GNUTranslations
[508] Fix | Delete
mofiles = find(domain, localedir, languages, all=True)
[509] Fix | Delete
if not mofiles:
[510] Fix | Delete
if fallback:
[511] Fix | Delete
return NullTranslations()
[512] Fix | Delete
raise OSError(ENOENT, 'No translation file found for domain', domain)
[513] Fix | Delete
# Avoid opening, reading, and parsing the .mo file after it's been done
[514] Fix | Delete
# once.
[515] Fix | Delete
result = None
[516] Fix | Delete
for mofile in mofiles:
[517] Fix | Delete
key = (class_, os.path.abspath(mofile))
[518] Fix | Delete
t = _translations.get(key)
[519] Fix | Delete
if t is None:
[520] Fix | Delete
with open(mofile, 'rb') as fp:
[521] Fix | Delete
t = _translations.setdefault(key, class_(fp))
[522] Fix | Delete
# Copy the translation object to allow setting fallbacks and
[523] Fix | Delete
# output charset. All other instance data is shared with the
[524] Fix | Delete
# cached object.
[525] Fix | Delete
t = copy.copy(t)
[526] Fix | Delete
if codeset:
[527] Fix | Delete
t.set_output_charset(codeset)
[528] Fix | Delete
if result is None:
[529] Fix | Delete
result = t
[530] Fix | Delete
else:
[531] Fix | Delete
result.add_fallback(t)
[532] Fix | Delete
return result
[533] Fix | Delete
[534] Fix | Delete
[535] Fix | Delete
def install(domain, localedir=None, codeset=None, names=None):
[536] Fix | Delete
t = translation(domain, localedir, fallback=True, codeset=codeset)
[537] Fix | Delete
t.install(names)
[538] Fix | Delete
[539] Fix | Delete
[540] Fix | Delete
[541] Fix | Delete
# a mapping b/w domains and locale directories
[542] Fix | Delete
_localedirs = {}
[543] Fix | Delete
# a mapping b/w domains and codesets
[544] Fix | Delete
_localecodesets = {}
[545] Fix | Delete
# current global domain, `messages' used for compatibility w/ GNU gettext
[546] Fix | Delete
_current_domain = 'messages'
[547] Fix | Delete
[548] Fix | Delete
[549] Fix | Delete
def textdomain(domain=None):
[550] Fix | Delete
global _current_domain
[551] Fix | Delete
if domain is not None:
[552] Fix | Delete
_current_domain = domain
[553] Fix | Delete
return _current_domain
[554] Fix | Delete
[555] Fix | Delete
[556] Fix | Delete
def bindtextdomain(domain, localedir=None):
[557] Fix | Delete
global _localedirs
[558] Fix | Delete
if localedir is not None:
[559] Fix | Delete
_localedirs[domain] = localedir
[560] Fix | Delete
return _localedirs.get(domain, _default_localedir)
[561] Fix | Delete
[562] Fix | Delete
[563] Fix | Delete
def bind_textdomain_codeset(domain, codeset=None):
[564] Fix | Delete
global _localecodesets
[565] Fix | Delete
if codeset is not None:
[566] Fix | Delete
_localecodesets[domain] = codeset
[567] Fix | Delete
return _localecodesets.get(domain)
[568] Fix | Delete
[569] Fix | Delete
[570] Fix | Delete
def dgettext(domain, message):
[571] Fix | Delete
try:
[572] Fix | Delete
t = translation(domain, _localedirs.get(domain, None),
[573] Fix | Delete
codeset=_localecodesets.get(domain))
[574] Fix | Delete
except OSError:
[575] Fix | Delete
return message
[576] Fix | Delete
return t.gettext(message)
[577] Fix | Delete
[578] Fix | Delete
def ldgettext(domain, message):
[579] Fix | Delete
codeset = _localecodesets.get(domain)
[580] Fix | Delete
try:
[581] Fix | Delete
t = translation(domain, _localedirs.get(domain, None), codeset=codeset)
[582] Fix | Delete
except OSError:
[583] Fix | Delete
return message.encode(codeset or locale.getpreferredencoding())
[584] Fix | Delete
return t.lgettext(message)
[585] Fix | Delete
[586] Fix | Delete
def dngettext(domain, msgid1, msgid2, n):
[587] Fix | Delete
try:
[588] Fix | Delete
t = translation(domain, _localedirs.get(domain, None),
[589] Fix | Delete
codeset=_localecodesets.get(domain))
[590] Fix | Delete
except OSError:
[591] Fix | Delete
if n == 1:
[592] Fix | Delete
return msgid1
[593] Fix | Delete
else:
[594] Fix | Delete
return msgid2
[595] Fix | Delete
return t.ngettext(msgid1, msgid2, n)
[596] Fix | Delete
[597] Fix | Delete
def ldngettext(domain, msgid1, msgid2, n):
[598] Fix | Delete
codeset = _localecodesets.get(domain)
[599] Fix | Delete
try:
[600] Fix | Delete
t = translation(domain, _localedirs.get(domain, None), codeset=codeset)
[601] Fix | Delete
except OSError:
[602] Fix | Delete
if n == 1:
[603] Fix | Delete
tmsg = msgid1
[604] Fix | Delete
else:
[605] Fix | Delete
tmsg = msgid2
[606] Fix | Delete
return tmsg.encode(codeset or locale.getpreferredencoding())
[607] Fix | Delete
return t.lngettext(msgid1, msgid2, n)
[608] Fix | Delete
[609] Fix | Delete
def gettext(message):
[610] Fix | Delete
return dgettext(_current_domain, message)
[611] Fix | Delete
[612] Fix | Delete
def lgettext(message):
[613] Fix | Delete
return ldgettext(_current_domain, message)
[614] Fix | Delete
[615] Fix | Delete
def ngettext(msgid1, msgid2, n):
[616] Fix | Delete
return dngettext(_current_domain, msgid1, msgid2, n)
[617] Fix | Delete
[618] Fix | Delete
def lngettext(msgid1, msgid2, n):
[619] Fix | Delete
return ldngettext(_current_domain, msgid1, msgid2, n)
[620] Fix | Delete
[621] Fix | Delete
# dcgettext() has been deemed unnecessary and is not implemented.
[622] Fix | Delete
[623] Fix | Delete
# James Henstridge's Catalog constructor from GNOME gettext. Documented usage
[624] Fix | Delete
# was:
[625] Fix | Delete
#
[626] Fix | Delete
# import gettext
[627] Fix | Delete
# cat = gettext.Catalog(PACKAGE, localedir=LOCALEDIR)
[628] Fix | Delete
# _ = cat.gettext
[629] Fix | Delete
# print _('Hello World')
[630] Fix | Delete
[631] Fix | Delete
# The resulting catalog object currently don't support access through a
[632] Fix | Delete
# dictionary API, which was supported (but apparently unused) in GNOME
[633] Fix | Delete
# gettext.
[634] Fix | Delete
[635] Fix | Delete
Catalog = translation
[636] Fix | Delete
[637] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function