]> git.pld-linux.org Git - packages/calibre.git/blobdiff - calibre-locales.patch
- up to 6.23.0
[packages/calibre.git] / calibre-locales.patch
index 106f977b530f0258cb146ff6bbead92a003fb133..f95f78472b7150dedb6f0cd5ddbe47ee433fb700 100644 (file)
---- calibre/src/calibre/utils/localization.py~ 2010-05-21 11:47:23.959845665 +0200
-+++ calibre/src/calibre/utils/localization.py  2010-05-21 11:47:07.293172188 +0200
-@@ -45,7 +45,7 @@
-     return lang
+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 messages_path(lang):
--    return P('localization/locales/%s/LC_MESSAGES'%lang)
-+    return ('/usr/share/locale/%s/LC_MESSAGES'%lang)
+     def mo_file(self, po_file):
+         locale = os.path.splitext(os.path.basename(po_file))[0]
+-        return locale, os.path.join(self.DEST, locale, 'messages.mo')
++        return locale, os.path.join(self.DEST, locale, 'LC_MESSAGES', 'messages.mo')
  
- def get_lc_messages_path(lang):
-     hlang = None
-@@ -75,9 +75,9 @@
+     def run(self, opts):
+         self.compile_main_translations()
+         self.compile_content_server_translations()
+-        self.freeze_locales()
+         self.compile_user_manual_translations()
+         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'
+-        from calibre import CurrentDir
+-        from calibre.utils.zipfile import ZipFile, ZIP_DEFLATED
+-        with ZipFile(zf, 'w', ZIP_DEFLATED) as zf:
+-            with CurrentDir(self.DEST):
+-                zf.add_dir('.')
+-        shutil.rmtree(self.DEST)
+-
+     @property
+     def stats(self):
+         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:
-             if buf is None:
--                buf = open(os.path.join(mpath, 'messages.mo'), 'rb')
+-            with ZipFile(get_path('localization/locales.zip',
+-                allow_user_override=False), 'r') as zf:
+-                try:
+-                    buf = io.BytesIO(zf.read(mpath + '/messages.mo'))
+-                except Exception:
+-                    pass
+-                else:
+-                    trans = GNUTranslations(buf)
+-                    _CACHE[lang] = trans
++           p = os.path.join(mpath, 'calibre.mo')
++           if os.path.exists(p):
++               trans = GNUTranslations(open(p, 'rb'))
++               _CACHE[lang] = trans
+     if trans is None:
+         return getattr(__builtins__, '_', lambda x: x)(text)
+     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)
++
+ def get_lc_messages_path(lang):
+     hlang = None
+-    if zf_exists():
+-        if lang in available_translations():
+-            hlang = lang
+-        else:
+-            xlang = lang.split('_')[0].lower()
+-            if xlang in available_translations():
+-                hlang = xlang
+-    return hlang
+-
+-
+-def zf_exists():
+-    return os.path.exists(P('localization/locales.zip',
+-                allow_user_override=False))
++    if lang in available_translations():
++        hlang = lang
++    else:
++        xlang = lang.split('_')[0]
++        if xlang in available_translations():
++            hlang = xlang
++    if hlang is not None:
++        return messages_path(hlang)
++    return None
+ _lang_trans = _country_trans = None
+ def get_all_translators():
+-    from zipfile import ZipFile
+-    with ZipFile(P('localization/locales.zip', allow_user_override=False), 'r') as zf:
+-        for lang in available_translations():
+-            mpath = get_lc_messages_path(lang)
+-            if mpath is not None:
+-                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
+ 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')
-             mpath = mpath.replace(os.sep+'nds'+os.sep, os.sep+'de'+os.sep)
--            isof = os.path.join(mpath, 'iso639.mo')
-+            isof = os.path.join(mpath, 'calibre_iso639.mo')
-             if os.path.exists(isof):
-                 iso639 = open(isof, 'rb')
---- calibre/src/calibre/startup.py~    2010-06-06 22:46:25.000000000 +0200
-+++ calibre/src/calibre/startup.py     2010-06-11 20:31:39.644201974 +0200
-@@ -49,7 +49,7 @@
-     # Setup translations
-     from calibre.utils.localization import set_translators
--    set_translators()
-+    #set_translators()
-     ################################################################################
-     # Initialize locale
++            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:
+-                    lcdata = msgpack_loads(zf.read(mpath + '/lcdata.calibre_msgpack'))
++                    lcdata = msgpack_loads(open(os.path.join(mpath, '/lcdata.calibre_msgpack')))
+                 except:
+                     pass  # No lcdata
This page took 0.194321 seconds and 4 git commands to generate.