1 diff -urNp -x '*.orig' calibre-4.20.0.org/setup/translations.py calibre-4.20.0/setup/translations.py
2 --- calibre-4.20.0.org/setup/translations.py 2020-07-03 04:11:13.000000000 +0200
3 +++ calibre-4.20.0/setup/translations.py 2021-06-23 14:08:43.642418411 +0200
4 @@ -304,12 +304,11 @@ class Translations(POT): # {{{
6 def mo_file(self, po_file):
7 locale = os.path.splitext(os.path.basename(po_file))[0]
8 - return locale, os.path.join(self.DEST, locale, 'messages.mo')
9 + return locale, os.path.join(self.DEST, locale, 'LC_MESSAGES', 'messages.mo')
12 self.compile_main_translations()
13 self.compile_content_server_translations()
14 - self.freeze_locales()
15 self.compile_user_manual_translations()
16 self.compile_website_translations()
17 self.compile_changelog_translations()
18 @@ -539,15 +538,6 @@ class Translations(POT): # {{{
19 zi.compress_type = ZIP_STORED if is_ci else ZIP_DEFLATED
22 - def freeze_locales(self):
23 - zf = self.DEST + '.zip'
24 - from calibre import CurrentDir
25 - from calibre.utils.zipfile import ZipFile, ZIP_DEFLATED
26 - with ZipFile(zf, 'w', ZIP_DEFLATED) as zf:
27 - with CurrentDir(self.DEST):
29 - shutil.rmtree(self.DEST)
33 return self.j(self.d(self.DEST), 'stats.calibre_msgpack')
34 diff -urNp -x '*.orig' calibre-4.20.0.org/src/calibre/translations/dynamic.py calibre-4.20.0/src/calibre/translations/dynamic.py
35 --- calibre-4.20.0.org/src/calibre/translations/dynamic.py 2020-07-03 04:11:13.000000000 +0200
36 +++ calibre-4.20.0/src/calibre/translations/dynamic.py 2021-06-23 14:08:43.642418411 +0200
37 @@ -24,15 +24,10 @@ def translate(lang, text):
39 mpath = get_lc_messages_path(lang)
41 - with ZipFile(get_path('localization/locales.zip',
42 - allow_user_override=False), 'r') as zf:
44 - buf = io.BytesIO(zf.read(mpath + '/messages.mo'))
48 - trans = GNUTranslations(buf)
49 - _CACHE[lang] = trans
50 + p = os.path.join(mpath, 'calibre.mo')
51 + if os.path.exists(p):
52 + trans = GNUTranslations(open(p, 'rb'))
53 + _CACHE[lang] = trans
55 return getattr(__builtins__, '_', lambda x: x)(text)
56 return trans.gettext(text)
57 diff -urNp -x '*.orig' calibre-4.20.0.org/src/calibre/utils/localization.py calibre-4.20.0/src/calibre/utils/localization.py
58 --- calibre-4.20.0.org/src/calibre/utils/localization.py 2020-07-03 04:11:13.000000000 +0200
59 +++ calibre-4.20.0/src/calibre/utils/localization.py 2021-06-23 14:08:43.642418411 +0200
60 @@ -104,51 +104,42 @@ def is_rtl():
61 return get_lang()[:2].lower() in {'he', 'ar'}
64 +def messages_path(lang):
65 + return ('/usr/share/locale/%s/LC_MESSAGES'%lang)
67 def get_lc_messages_path(lang):
70 - if lang in available_translations():
73 - xlang = lang.split('_')[0].lower()
74 - if xlang in available_translations():
80 - return os.path.exists(P('localization/locales.zip',
81 - allow_user_override=False))
82 + if lang in available_translations():
85 + xlang = lang.split('_')[0]
86 + if xlang in available_translations():
88 + if hlang is not None:
89 + return messages_path(hlang)
93 _lang_trans = _country_trans = None
96 def get_all_translators():
97 - from zipfile import ZipFile
98 - with ZipFile(P('localization/locales.zip', allow_user_override=False), 'r') as zf:
99 - for lang in available_translations():
100 - mpath = get_lc_messages_path(lang)
101 - if mpath is not None:
102 - buf = io.BytesIO(zf.read(mpath + '/messages.mo'))
103 + for lang in available_translations():
104 + mpath = get_lc_messages_path(lang)
105 + if mpath is not None:
107 + buf = open(os.path.join(mpath, 'calibre.mo'), 'rb')
108 yield lang, GNUTranslations(buf)
113 def get_single_translator(mpath, which='messages'):
114 - from zipfile import ZipFile
115 - with ZipFile(P('localization/locales.zip', allow_user_override=False), 'r') as zf:
116 - path = f'{mpath}/{which}.mo'
117 - data = zf.read(path)
118 - buf = io.BytesIO(data)
120 + buf = open(os.path.join(mpath, '/%s.mo' % which), 'rb')
121 return GNUTranslations(buf)
122 except Exception as e:
124 - traceback.print_exc()
126 - sig = hashlib.sha1(data).hexdigest()
127 - raise ValueError('Failed to load translations for: {} (size: {} and signature: {}) with error: {}'.format(
128 - path, len(data), sig, e))
129 + pass # No translations for this lang
132 def get_iso639_translator(lang):
133 @@ -219,27 +210,25 @@ def translator_for_lang(lang):
134 buf = load_po(mpath + '.po')
136 if mpath is not None:
137 - from zipfile import ZipFile
138 - with ZipFile(P('localization/locales.zip',
139 - allow_user_override=False), 'r') as zf:
141 - buf = io.BytesIO(zf.read(mpath + '/messages.mo'))
144 + buf = open(os.path.join(mpath, 'calibre.mo'), 'rb')
146 + pass # No translations for this lang
149 - isof = mpath + '/iso639.mo'
151 - iso639 = io.BytesIO(zf.read(isof))
152 + iso639 = open(os.path.join(mpath, 'calibre_iso639.mo'), 'rb')
154 pass # No iso639 translations for this lang
155 - isof = mpath + '/iso3166.mo'
157 - iso3166 = io.BytesIO(zf.read(isof))
158 + iso3166 = open(os.path.join(mpath, 'calibre_iso3166.mo'), 'rb')
160 pass # No iso3166 translations for this lang
162 from calibre.utils.serialize import msgpack_loads
164 - lcdata = msgpack_loads(zf.read(mpath + '/lcdata.calibre_msgpack'))
165 + lcdata = msgpack_loads(open(os.path.join(mpath, '/lcdata.calibre_msgpack')))