]> git.pld-linux.org Git - packages/calibre.git/blob - calibre-locales.patch
- up to 6.23.0
[packages/calibre.git] / calibre-locales.patch
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):  # {{{
5  
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')
10  
11      def run(self, opts):
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
20                      zf.writestr(zi, raw)
21  
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):
28 -                zf.add_dir('.')
29 -        shutil.rmtree(self.DEST)
30 -
31      @property
32      def stats(self):
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):
38      else:
39          mpath = get_lc_messages_path(lang)
40          if mpath is not None:
41 -            with ZipFile(get_path('localization/locales.zip',
42 -                allow_user_override=False), 'r') as zf:
43 -                try:
44 -                    buf = io.BytesIO(zf.read(mpath + '/messages.mo'))
45 -                except Exception:
46 -                    pass
47 -                else:
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
54      if trans is None:
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'}
62  
63  
64 +def messages_path(lang):
65 +    return ('/usr/share/locale/%s/LC_MESSAGES'%lang)
66 +
67  def get_lc_messages_path(lang):
68      hlang = None
69 -    if zf_exists():
70 -        if lang in available_translations():
71 -            hlang = lang
72 -        else:
73 -            xlang = lang.split('_')[0].lower()
74 -            if xlang in available_translations():
75 -                hlang = xlang
76 -    return hlang
77 -
78 -
79 -def zf_exists():
80 -    return os.path.exists(P('localization/locales.zip',
81 -                allow_user_override=False))
82 +    if lang in available_translations():
83 +        hlang = lang
84 +    else:
85 +        xlang = lang.split('_')[0]
86 +        if xlang in available_translations():
87 +            hlang = xlang
88 +    if hlang is not None:
89 +        return messages_path(hlang)
90 +    return None
91  
92  
93  _lang_trans = _country_trans = None
94  
95  
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:
106 +            try:
107 +                buf = open(os.path.join(mpath, 'calibre.mo'), 'rb')
108                  yield lang, GNUTranslations(buf)
109 +            except:
110 +                pass
111  
112  
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)
119          try:
120 +            buf = open(os.path.join(mpath, '/%s.mo' % which), 'rb')
121              return GNUTranslations(buf)
122          except Exception as e:
123 -            import traceback
124 -            traceback.print_exc()
125 -            import hashlib
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
130  
131  
132  def get_iso639_translator(lang):
133 @@ -219,27 +210,25 @@ def translator_for_lang(lang):
134          buf = load_po(mpath + '.po')
135  
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:
140 -            if buf is None:
141 -                buf = io.BytesIO(zf.read(mpath + '/messages.mo'))
142 +        if buf is None:
143 +            try:
144 +                buf = open(os.path.join(mpath, 'calibre.mo'), 'rb')
145 +            except:
146 +                pass  # No translations for this lang
147              if mpath == 'nds':
148                  mpath = 'de'
149 -            isof = mpath + '/iso639.mo'
150              try:
151 -                iso639 = io.BytesIO(zf.read(isof))
152 +                iso639 = open(os.path.join(mpath, 'calibre_iso639.mo'), 'rb')
153              except:
154                  pass  # No iso639 translations for this lang
155 -            isof = mpath + '/iso3166.mo'
156              try:
157 -                iso3166 = io.BytesIO(zf.read(isof))
158 +                iso3166 = open(os.path.join(mpath, 'calibre_iso3166.mo'), 'rb')
159              except:
160                  pass  # No iso3166 translations for this lang
161              if buf is not None:
162                  from calibre.utils.serialize import msgpack_loads
163                  try:
164 -                    lcdata = msgpack_loads(zf.read(mpath + '/lcdata.calibre_msgpack'))
165 +                    lcdata = msgpack_loads(open(os.path.join(mpath, '/lcdata.calibre_msgpack')))
166                  except:
167                      pass  # No lcdata
168  
This page took 0.048265 seconds and 3 git commands to generate.