---- calibre/setup/translations.py.wiget 2013-12-06 05:13:34.000000000 +0100
-+++ calibre/setup/translations.py 2013-12-09 09:28:32.349958101 +0100
-@@ -143,7 +143,7 @@ class Translations(POT): # {{{
+diff -urNp -x '*.orig' calibre-4.20.0.org/setup/translations.py calibre-4.20.0/setup/translations.py
+--- calibre-4.20.0.org/setup/translations.py 2020-07-03 04:11:13.000000000 +0200
++++ calibre-4.20.0/setup/translations.py 2021-06-23 14:08:43.642418411 +0200
+@@ -304,12 +304,11 @@ class Translations(POT): # {{{
def mo_file(self, po_file):
locale = os.path.splitext(os.path.basename(po_file))[0]
+ return locale, os.path.join(self.DEST, locale, 'LC_MESSAGES', 'messages.mo')
def run(self, opts):
- self.iso639_errors = []
-@@ -152,7 +152,8 @@ class Translations(POT): # {{{
- base = os.path.dirname(dest)
- if not os.path.exists(base):
- os.makedirs(base)
-- jobs.append(['msgfmt', '-o', dest, f])
-+ if self.newer(dest, f):
-+ jobs.append(['msgfmt', '-o', dest, f])
- iscpo = {'bn':'bn_IN', 'zh_HK':'zh_CN'}.get(locale, locale)
- iso639 = self.j(self.LP_ISO_PATH, '%s.po'%iscpo)
-
-@@ -174,7 +175,6 @@ class Translations(POT): # {{{
- raise SystemExit(1)
-
- self.write_stats()
+ self.compile_main_translations()
+ self.compile_content_server_translations()
- self.freeze_locales()
self.compile_user_manual_translations()
-
- def check_iso639(self, path):
-@@ -198,15 +198,6 @@ class Translations(POT): # {{{
- # raise SystemExit(1)
- rmap[msgstr] = msgid
+ self.compile_website_translations()
+ self.compile_changelog_translations()
+@@ -539,15 +538,6 @@ class Translations(POT): # {{{
+ zi.compress_type = ZIP_STORED if is_ci else ZIP_DEFLATED
+ zf.writestr(zi, raw)
- def freeze_locales(self):
- zf = self.DEST + '.zip'
-
@property
def stats(self):
- return self.j(self.d(self.DEST), 'stats.pickle')
---- calibre/src/calibre/translations/dynamic.py.wiget 2013-12-06 05:13:34.000000000 +0100
-+++ calibre/src/calibre/translations/dynamic.py 2013-12-09 09:28:32.349958101 +0100
-@@ -5,10 +5,10 @@ Dynamic language lookup of translations
- __license__ = 'GPL v3'
- __copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
-
-+import os
- import cStringIO
- from gettext import GNUTranslations
- from calibre.utils.localization import get_lc_messages_path
--from zipfile import ZipFile
-
- __all__ = ['translate']
-
-@@ -21,15 +21,10 @@ def translate(lang, text):
+ return self.j(self.d(self.DEST), 'stats.calibre_msgpack')
+diff -urNp -x '*.orig' calibre-4.20.0.org/src/calibre/translations/dynamic.py calibre-4.20.0/src/calibre/translations/dynamic.py
+--- calibre-4.20.0.org/src/calibre/translations/dynamic.py 2020-07-03 04:11:13.000000000 +0200
++++ calibre-4.20.0/src/calibre/translations/dynamic.py 2021-06-23 14:08:43.642418411 +0200
+@@ -24,15 +24,10 @@ def translate(lang, text):
else:
mpath = get_lc_messages_path(lang)
if mpath is not None:
-- with ZipFile(P('localization/locales.zip',
+- with ZipFile(get_path('localization/locales.zip',
- allow_user_override=False), 'r') as zf:
- try:
-- buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
-- except:
+- buf = io.BytesIO(zf.read(mpath + '/messages.mo'))
+- except Exception:
- pass
- else:
- trans = GNUTranslations(buf)
+ _CACHE[lang] = trans
if trans is None:
return getattr(__builtins__, '_', lambda x: x)(text)
- return trans.ugettext(text)
---- calibre/src/calibre/utils/localization.py.wiget 2013-12-06 05:13:34.000000000 +0100
-+++ calibre/src/calibre/utils/localization.py 2013-12-09 09:31:05.694326467 +0100
-@@ -74,20 +74,20 @@ def get_lang():
- lang = 'en'
- return lang
+ return trans.gettext(text)
+diff -urNp -x '*.orig' calibre-4.20.0.org/src/calibre/utils/localization.py calibre-4.20.0/src/calibre/utils/localization.py
+--- calibre-4.20.0.org/src/calibre/utils/localization.py 2020-07-03 04:11:13.000000000 +0200
++++ calibre-4.20.0/src/calibre/utils/localization.py 2021-06-23 14:08:43.642418411 +0200
+@@ -104,51 +104,42 @@ def is_rtl():
+ return get_lang()[:2].lower() in {'he', 'ar'}
+
+def messages_path(lang):
+ return ('/usr/share/locale/%s/LC_MESSAGES'%lang)
- hlang = xlang
- return hlang
-
+-
-def zf_exists():
- return os.path.exists(P('localization/locales.zip',
- allow_user_override=False))
+ return messages_path(hlang)
+ return None
- _lang_trans = None
-@@ -99,13 +99,14 @@
- _lang_trans = None
+ _lang_trans = _country_trans = None
+
def get_all_translators():
- from zipfile import ZipFile
- for lang in available_translations():
- mpath = get_lc_messages_path(lang)
- if mpath is not None:
-- buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
-- yield lang, GNUTranslations(buf)
+- buf = io.BytesIO(zf.read(mpath + '/messages.mo'))
+ for lang in available_translations():
+ mpath = get_lc_messages_path(lang)
+ if mpath is not None:
+ try:
+ buf = open(os.path.join(mpath, 'calibre.mo'), 'rb')
+ yield lang, GNUTranslations(buf)
+ except:
+ pass
-+ yield lang, GNUTranslations(buf)
- lcdata = {
- u'abday': (u'Sun', u'Mon', u'Tue', u'Wed', u'Thu', u'Fri', u'Sat'),
-@@ -145,21 +145,20 @@
- buf = cStringIO.StringIO(buf.getvalue())
- if mpath is not None:
-- from zipfile import ZipFile
-- with ZipFile(P('localization/locales.zip',
-- allow_user_override=False), 'r') as zf:
-- if buf is None:
-- buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
-+ if buf is None:
-+ try:
-+ buf = open(os.path.join(mpath, 'calibre.mo'), 'rb')
-+ except:
-+ pass # No translations for this lang
- if mpath == 'nds':
- mpath = 'de'
-- isof = mpath + '/iso639.mo'
+ def get_single_translator(mpath, which='messages'):
+- from zipfile import ZipFile
+- with ZipFile(P('localization/locales.zip', allow_user_override=False), 'r') as zf:
+- path = f'{mpath}/{which}.mo'
+- data = zf.read(path)
+- buf = io.BytesIO(data)
+ try:
++ buf = open(os.path.join(mpath, '/%s.mo' % which), 'rb')
+ return GNUTranslations(buf)
+ except Exception as e:
+- import traceback
+- traceback.print_exc()
+- import hashlib
+- sig = hashlib.sha1(data).hexdigest()
+- raise ValueError('Failed to load translations for: {} (size: {} and signature: {}) with error: {}'.format(
+- path, len(data), sig, e))
++ pass # No translations for this lang
+
+
+ def get_iso639_translator(lang):
+@@ -219,27 +210,25 @@ def translator_for_lang(lang):
+ buf = load_po(mpath + '.po')
+
+ if mpath is not None:
+- from zipfile import ZipFile
+- with ZipFile(P('localization/locales.zip',
+- allow_user_override=False), 'r') as zf:
+- if buf is None:
+- buf = io.BytesIO(zf.read(mpath + '/messages.mo'))
++ if buf is None:
++ try:
++ buf = open(os.path.join(mpath, 'calibre.mo'), 'rb')
++ except:
++ pass # No translations for this lang
+ if mpath == 'nds':
+ mpath = 'de'
+- isof = mpath + '/iso639.mo'
+ try:
+- iso639 = io.BytesIO(zf.read(isof))
++ iso639 = open(os.path.join(mpath, 'calibre_iso639.mo'), 'rb')
+ except:
+ pass # No iso639 translations for this lang
+- isof = mpath + '/iso3166.mo'
+ try:
+- iso3166 = io.BytesIO(zf.read(isof))
++ iso3166 = open(os.path.join(mpath, 'calibre_iso3166.mo'), 'rb')
+ except:
+ pass # No iso3166 translations for this lang
+ if buf is not None:
+ from calibre.utils.serialize import msgpack_loads
try:
-- iso639 = cStringIO.StringIO(zf.read(isof))
-+ iso639 = open(os.path.join(mpath, 'calibre_iso639.mo'), 'rb')
+- lcdata = msgpack_loads(zf.read(mpath + '/lcdata.calibre_msgpack'))
++ lcdata = msgpack_loads(open(os.path.join(mpath, '/lcdata.calibre_msgpack')))
except:
- pass # No iso639 translations for this lang
- if buf is not None:
- try:
-- lcdata = cPickle.loads(zf.read(mpath + '/lcdata.pickle'))
-+ lcdata = cPickle.loads(open(os.path.join(mpath, 'calibre_lcdata.pickle')))
- except:
- pass # No lcdata
+ pass # No lcdata