]> git.pld-linux.org Git - packages/calibre.git/blame - calibre-locales.patch
- up to 6.23.0
[packages/calibre.git] / calibre-locales.patch
CommitLineData
d770c022
JR
1diff -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): # {{{
2d44714a
AF
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
66f13bde
JR
11 def run(self, opts):
12 self.compile_main_translations()
13 self.compile_content_server_translations()
2d44714a 14- self.freeze_locales()
270a5ef0 15 self.compile_user_manual_translations()
d770c022
JR
16 self.compile_website_translations()
17 self.compile_changelog_translations()
18@@ -539,15 +538,6 @@ class Translations(POT): # {{{
4d780bcf
JR
19 zi.compress_type = ZIP_STORED if is_ci else ZIP_DEFLATED
20 zf.writestr(zi, raw)
2d44714a
AF
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):
d770c022
JR
33 return self.j(self.d(self.DEST), 'stats.calibre_msgpack')
34diff -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):
2d44714a
AF
38 else:
39 mpath = get_lc_messages_path(lang)
40 if mpath is not None:
4d780bcf 41- with ZipFile(get_path('localization/locales.zip',
2d44714a
AF
42- allow_user_override=False), 'r') as zf:
43- try:
7b172d7e 44- buf = io.BytesIO(zf.read(mpath + '/messages.mo'))
394abe07 45- except Exception:
2d44714a
AF
46- pass
47- else:
48- trans = GNUTranslations(buf)
49- _CACHE[lang] = trans
270a5ef0 50+ p = os.path.join(mpath, 'calibre.mo')
2d44714a
AF
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)
49a96cf0 56 return trans.gettext(text)
d770c022
JR
57diff -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():
66f13bde
JR
61 return get_lang()[:2].lower() in {'he', 'ar'}
62
b65e37c7 63
e69f76cd
JK
64+def messages_path(lang):
65+ return ('/usr/share/locale/%s/LC_MESSAGES'%lang)
5cfefa9c 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:
591b7d3d 73- xlang = lang.split('_')[0].lower()
5cfefa9c 74- if xlang in available_translations():
75- hlang = xlang
76- return hlang
77-
66f13bde 78-
5cfefa9c 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
270a5ef0
JR
88+ if hlang is not None:
89+ return messages_path(hlang)
90+ return None
b65e37c7 91
2d44714a 92
4d780bcf 93 _lang_trans = _country_trans = None
270a5ef0 94
d770c022 95
270a5ef0
JR
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:
7b172d7e 102- buf = io.BytesIO(zf.read(mpath + '/messages.mo'))
270a5ef0
JR
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')
d770c022 108 yield lang, GNUTranslations(buf)
270a5ef0
JR
109+ except:
110+ pass
270a5ef0 111
7b172d7e
JR
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:
49a96cf0 116- path = f'{mpath}/{which}.mo'
394abe07
JR
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
7b172d7e
JR
130
131
132 def get_iso639_translator(lang):
4d780bcf 133@@ -219,27 +210,25 @@ def translator_for_lang(lang):
43b56935 134 buf = load_po(mpath + '.po')
b65e37c7 135
43b56935
JR
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
4d780bcf
JR
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
43b56935
JR
161 if buf is not None:
162 from calibre.utils.serialize import msgpack_loads
270a5ef0 163 try:
43b56935
JR
164- lcdata = msgpack_loads(zf.read(mpath + '/lcdata.calibre_msgpack'))
165+ lcdata = msgpack_loads(open(os.path.join(mpath, '/lcdata.calibre_msgpack')))
270a5ef0 166 except:
43b56935 167 pass # No lcdata
b65e37c7 168
This page took 0.157908 seconds and 4 git commands to generate.