mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: Port calls to ugettext()
This commit is contained in:
parent
67814d2186
commit
930376c036
@ -18,6 +18,7 @@ from datetime import date
|
|||||||
base = os.path.dirname(os.path.abspath(__file__))
|
base = os.path.dirname(os.path.abspath(__file__))
|
||||||
sys.path.append(base)
|
sys.path.append(base)
|
||||||
sys.path.insert(0, os.path.dirname(base))
|
sys.path.insert(0, os.path.dirname(base))
|
||||||
|
ispy3 = sys.version_info.major > 2
|
||||||
from setup import __appname__, __version__
|
from setup import __appname__, __version__
|
||||||
import calibre.utils.localization as l # Ensure calibre translations are installed
|
import calibre.utils.localization as l # Ensure calibre translations are installed
|
||||||
import custom
|
import custom
|
||||||
@ -100,7 +101,7 @@ if language not in {'en', 'eng'}:
|
|||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
title = t.ugettext(title)
|
title = getattr(t, 'gettext' if ispy3 else 'ugettext')(title)
|
||||||
|
|
||||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||||
# add_function_parentheses = True
|
# add_function_parentheses = True
|
||||||
|
@ -12,6 +12,7 @@ from collections import OrderedDict
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from calibre import as_unicode
|
from calibre import as_unicode
|
||||||
|
from calibre.constants import ispy3
|
||||||
from calibre.customize import (Plugin, numeric_version, platform,
|
from calibre.customize import (Plugin, numeric_version, platform,
|
||||||
InvalidPlugin, PluginNotFound)
|
InvalidPlugin, PluginNotFound)
|
||||||
from polyglot.builtins import (itervalues, map, string_or_bytes,
|
from polyglot.builtins import (itervalues, map, string_or_bytes,
|
||||||
@ -111,7 +112,7 @@ def load_translations(namespace, zfp):
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
trans = _translations_cache[zfp] = GNUTranslations(BytesIO(mo))
|
trans = _translations_cache[zfp] = GNUTranslations(BytesIO(mo))
|
||||||
|
|
||||||
namespace['_'] = trans.ugettext
|
namespace['_'] = getattr(trans, 'gettext' if ispy3 else 'ugettext')
|
||||||
namespace['ngettext'] = trans.ungettext
|
namespace['ngettext'] = trans.ungettext
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ from subprocess import check_call, check_output
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from calibre import __appname__, prints, guess_type
|
from calibre import __appname__, prints, guess_type
|
||||||
from calibre.constants import islinux, isbsd
|
from calibre.constants import islinux, isbsd, ispy3
|
||||||
from calibre.customize.ui import all_input_formats
|
from calibre.customize.ui import all_input_formats
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
from calibre import CurrentDir
|
from calibre import CurrentDir
|
||||||
@ -1103,7 +1103,7 @@ def write_appdata(key, entry, base, translators):
|
|||||||
for para in entry['description']:
|
for para in entry['description']:
|
||||||
description.append(E.p(para))
|
description.append(E.p(para))
|
||||||
for lang, t in iteritems(translators):
|
for lang, t in iteritems(translators):
|
||||||
tp = t.ugettext(para)
|
tp = getattr(t, 'gettext' if ispy3 else 'ugettext')(para)
|
||||||
if tp != para:
|
if tp != para:
|
||||||
description.append(E.p(tp))
|
description.append(E.p(tp))
|
||||||
description[-1].set('{http://www.w3.org/XML/1998/namespace}lang', lang)
|
description[-1].set('{http://www.w3.org/XML/1998/namespace}lang', lang)
|
||||||
@ -1120,7 +1120,7 @@ def write_appdata(key, entry, base, translators):
|
|||||||
type='desktop'
|
type='desktop'
|
||||||
)
|
)
|
||||||
for lang, t in iteritems(translators):
|
for lang, t in iteritems(translators):
|
||||||
tp = t.ugettext(entry['summary'])
|
tp = getattr(t, 'gettext' if ispy3 else 'ugettext')(entry['summary'])
|
||||||
if tp != entry['summary']:
|
if tp != entry['summary']:
|
||||||
root.append(E.summary(tp))
|
root.append(E.summary(tp))
|
||||||
root[-1].set('{http://www.w3.org/XML/1998/namespace}lang', lang)
|
root[-1].set('{http://www.w3.org/XML/1998/namespace}lang', lang)
|
||||||
|
@ -16,7 +16,7 @@ from functools import wraps
|
|||||||
from polyglot.builtins import iteritems, itervalues, reraise, map, is_py3
|
from polyglot.builtins import iteritems, itervalues, reraise, map, is_py3
|
||||||
|
|
||||||
from calibre import guess_type, force_unicode
|
from calibre import guess_type, force_unicode
|
||||||
from calibre.constants import __version__, plugins
|
from calibre.constants import __version__, plugins, ispy3
|
||||||
from calibre.srv.loop import WRITE
|
from calibre.srv.loop import WRITE
|
||||||
from calibre.srv.errors import HTTPSimpleResponse
|
from calibre.srv.errors import HTTPSimpleResponse
|
||||||
from calibre.srv.http_request import HTTPRequest, read_headers
|
from calibre.srv.http_request import HTTPRequest, read_headers
|
||||||
@ -288,8 +288,8 @@ class RequestData(object): # {{{
|
|||||||
if lang_code != self.lang_code:
|
if lang_code != self.lang_code:
|
||||||
found, lang, t = self.get_translator(lang_code)
|
found, lang, t = self.get_translator(lang_code)
|
||||||
self.lang_code = lang
|
self.lang_code = lang
|
||||||
self.gettext_func = t.ugettext
|
self.gettext_func = getattr(t, 'gettext' if ispy3 else 'ugettext')
|
||||||
self.ngettext_func = t.ungettext
|
self.ngettext_func = getattr(t, 'ngettext' if ispy3 else 'ungettext')
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ from io import BytesIO
|
|||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
|
|
||||||
from calibre import guess_type
|
from calibre import guess_type
|
||||||
|
from calibre.constants import ispy3
|
||||||
from calibre.srv.tests.base import BaseTest, TestServer
|
from calibre.srv.tests.base import BaseTest, TestServer
|
||||||
from calibre.srv.utils import eintr_retry_call
|
from calibre.srv.utils import eintr_retry_call
|
||||||
from calibre.utils.monotonic import monotonic
|
from calibre.utils.monotonic import monotonic
|
||||||
@ -96,7 +97,7 @@ class TestHTTP(BaseTest):
|
|||||||
conn.request('GET', '/', headers={'Accept-Language': al})
|
conn.request('GET', '/', headers={'Accept-Language': al})
|
||||||
r = conn.getresponse()
|
r = conn.getresponse()
|
||||||
self.ae(r.status, http_client.OK)
|
self.ae(r.status, http_client.OK)
|
||||||
q += get_translator(q)[-1].ugettext('Unknown')
|
q += getattr(get_translator(q)[-1], 'gettext' if ispy3 else 'ugettext')('Unknown')
|
||||||
self.ae(r.read(), q)
|
self.ae(r.read(), q)
|
||||||
|
|
||||||
test('en', 'en')
|
test('en', 'en')
|
||||||
|
@ -6,7 +6,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os, locale, re, io
|
import os, locale, re, io, sys
|
||||||
from gettext import GNUTranslations, NullTranslations
|
from gettext import GNUTranslations, NullTranslations
|
||||||
|
|
||||||
from polyglot.builtins import is_py3, iteritems, unicode_type
|
from polyglot.builtins import is_py3, iteritems, unicode_type
|
||||||
@ -380,7 +380,8 @@ def get_language(lang):
|
|||||||
# The translator was not active when _extra_lang_codes was defined, so
|
# The translator was not active when _extra_lang_codes was defined, so
|
||||||
# re-translate
|
# re-translate
|
||||||
return translate(_extra_lang_codes[lang])
|
return translate(_extra_lang_codes[lang])
|
||||||
return get_iso_language(getattr(_lang_trans, 'ugettext', translate), lang)
|
attr = 'gettext' if sys.version_info.major > 2 else 'ugettext'
|
||||||
|
return get_iso_language(getattr(_lang_trans, attr, translate), lang)
|
||||||
|
|
||||||
|
|
||||||
def calibre_langcode_to_name(lc, localize=True):
|
def calibre_langcode_to_name(lc, localize=True):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user