Another couple of ispy3

This commit is contained in:
Kovid Goyal 2019-12-19 15:57:41 +05:30
parent c4eedda5f2
commit 151fa406f6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 3 additions and 6 deletions

View File

@ -8,7 +8,6 @@ __copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
import io
from gettext import GNUTranslations
from calibre.constants import ispy3
from calibre.utils.localization import get_lc_messages_path
from zipfile import ZipFile
@ -35,5 +34,4 @@ def translate(lang, text):
_CACHE[lang] = trans
if trans is None:
return getattr(__builtins__, '_', lambda x: x)(text)
f = getattr(trans, 'gettext' if ispy3 else 'ugettext')
return f(text)
return trans.gettext(text)

View File

@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import os, locale, re, io, sys
import os, locale, re, io
from gettext import GNUTranslations, NullTranslations
from polyglot.builtins import iteritems, unicode_type
@ -402,8 +402,7 @@ def get_language(lang, gettext_func=None):
# re-translate
return translate(_extra_lang_codes[lang])
if gettext_func is None:
attr = 'gettext' if sys.version_info.major > 2 else 'ugettext'
gettext_func = getattr(_lang_trans, attr, translate)
gettext_func = getattr(_lang_trans, 'gettext', translate)
return get_iso_language(gettext_func, lang)