]>
Commit | Line | Data |
---|---|---|
2d44714a AF |
1 | --- calibre/setup/translations.py.wiget 2013-12-06 05:13:34.000000000 +0100 |
2 | +++ calibre/setup/translations.py 2013-12-09 09:28:32.349958101 +0100 | |
3 | @@ -143,7 +143,7 @@ class Translations(POT): # {{{ | |
4 | ||
5 | def mo_file(self, po_file): | |
6 | locale = os.path.splitext(os.path.basename(po_file))[0] | |
7 | - return locale, os.path.join(self.DEST, locale, 'messages.mo') | |
8 | + return locale, os.path.join(self.DEST, locale, 'LC_MESSAGES', 'messages.mo') | |
9 | ||
10 | def run(self, opts): | |
11 | self.iso639_errors = [] | |
2d44714a | 12 | @@ -174,7 +175,6 @@ class Translations(POT): # {{{ |
66f13bde JR |
13 | def run(self, opts): |
14 | self.compile_main_translations() | |
15 | self.compile_content_server_translations() | |
2d44714a | 16 | - self.freeze_locales() |
270a5ef0 | 17 | self.compile_user_manual_translations() |
2d44714a | 18 | |
66f13bde | 19 | def compile_group(self, files, handle_stats=None, file_ok=None, action_per_file=None): |
2d44714a AF |
20 | @@ -198,15 +198,6 @@ class Translations(POT): # {{{ |
21 | # raise SystemExit(1) | |
22 | rmap[msgstr] = msgid | |
23 | ||
24 | - def freeze_locales(self): | |
25 | - zf = self.DEST + '.zip' | |
26 | - from calibre import CurrentDir | |
27 | - from calibre.utils.zipfile import ZipFile, ZIP_DEFLATED | |
28 | - with ZipFile(zf, 'w', ZIP_DEFLATED) as zf: | |
29 | - with CurrentDir(self.DEST): | |
30 | - zf.add_dir('.') | |
31 | - shutil.rmtree(self.DEST) | |
32 | - | |
33 | @property | |
34 | def stats(self): | |
35 | return self.j(self.d(self.DEST), 'stats.pickle') | |
36 | --- calibre/src/calibre/translations/dynamic.py.wiget 2013-12-06 05:13:34.000000000 +0100 | |
37 | +++ calibre/src/calibre/translations/dynamic.py 2013-12-09 09:28:32.349958101 +0100 | |
2d44714a AF |
38 | @@ -21,15 +21,10 @@ def translate(lang, text): |
39 | else: | |
40 | mpath = get_lc_messages_path(lang) | |
41 | if mpath is not None: | |
42 | - with ZipFile(P('localization/locales.zip', | |
43 | - allow_user_override=False), 'r') as zf: | |
44 | - try: | |
7b172d7e | 45 | - buf = io.BytesIO(zf.read(mpath + '/messages.mo')) |
394abe07 | 46 | - except Exception: |
2d44714a AF |
47 | - pass |
48 | - else: | |
49 | - trans = GNUTranslations(buf) | |
50 | - _CACHE[lang] = trans | |
270a5ef0 | 51 | + p = os.path.join(mpath, 'calibre.mo') |
2d44714a AF |
52 | + if os.path.exists(p): |
53 | + trans = GNUTranslations(open(p, 'rb')) | |
54 | + _CACHE[lang] = trans | |
55 | if trans is None: | |
56 | return getattr(__builtins__, '_', lambda x: x)(text) | |
57 | return trans.ugettext(text) | |
58 | --- calibre/src/calibre/utils/localization.py.wiget 2013-12-06 05:13:34.000000000 +0100 | |
59 | +++ calibre/src/calibre/utils/localization.py 2013-12-09 09:31:05.694326467 +0100 | |
66f13bde JR |
60 | @@ -74,21 +74,20 @@ def get_lang(): |
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 AF |
92 | _lang_trans = None |
93 | ||
270a5ef0 JR |
94 | @@ -99,13 +99,14 @@ |
95 | _lang_trans = None | |
96 | ||
97 | def get_all_translators(): | |
98 | - from zipfile import ZipFile | |
99 | - with ZipFile(P('localization/locales.zip', allow_user_override=False), 'r') as zf: | |
100 | - for lang in available_translations(): | |
101 | - mpath = get_lc_messages_path(lang) | |
102 | - if mpath is not None: | |
7b172d7e | 103 | - buf = io.BytesIO(zf.read(mpath + '/messages.mo')) |
270a5ef0 JR |
104 | - yield lang, GNUTranslations(buf) |
105 | + for lang in available_translations(): | |
106 | + mpath = get_lc_messages_path(lang) | |
107 | + if mpath is not None: | |
108 | + try: | |
109 | + buf = open(os.path.join(mpath, 'calibre.mo'), 'rb') | |
8deb663e | 110 | + yield lang, GNUTranslations(buf) |
270a5ef0 JR |
111 | + except: |
112 | + pass | |
270a5ef0 JR |
113 | |
114 | lcdata = { | |
115 | u'abday': (u'Sun', u'Mon', u'Tue', u'Wed', u'Thu', u'Fri', u'Sat'), | |
394abe07 | 116 | @@ -134,20 +134,11 @@ |
7b172d7e JR |
117 | |
118 | ||
119 | def get_single_translator(mpath, which='messages'): | |
120 | - from zipfile import ZipFile | |
121 | - with ZipFile(P('localization/locales.zip', allow_user_override=False), 'r') as zf: | |
394abe07 JR |
122 | - path = '{}/{}.mo'.format(mpath, which) |
123 | - data = zf.read(path) | |
124 | - buf = io.BytesIO(data) | |
125 | try: | |
126 | + buf = open(os.path.join(mpath, '/%s.mo' % which), 'rb') | |
127 | return GNUTranslations(buf) | |
128 | except Exception as e: | |
129 | - import traceback | |
130 | - traceback.print_exc() | |
131 | - import hashlib | |
132 | - sig = hashlib.sha1(data).hexdigest() | |
133 | - raise ValueError('Failed to load translations for: {} (size: {} and signature: {}) with error: {}'.format( | |
134 | - path, len(data), sig, e)) | |
135 | + pass # No translations for this lang | |
7b172d7e JR |
136 | |
137 | ||
138 | def get_iso639_translator(lang): | |
139 | @@ -145,22 +145,21 @@ | |
43b56935 | 140 | buf = load_po(mpath + '.po') |
b65e37c7 | 141 | |
43b56935 JR |
142 | if mpath is not None: |
143 | - from zipfile import ZipFile | |
144 | - with ZipFile(P('localization/locales.zip', | |
145 | - allow_user_override=False), 'r') as zf: | |
146 | - if buf is None: | |
147 | - buf = io.BytesIO(zf.read(mpath + '/messages.mo')) | |
148 | + if buf is None: | |
149 | + try: | |
150 | + buf = open(os.path.join(mpath, 'calibre.mo'), 'rb') | |
151 | + except: | |
152 | + pass # No translations for this lang | |
153 | if mpath == 'nds': | |
154 | mpath = 'de' | |
155 | - isof = mpath + '/iso639.mo' | |
156 | try: | |
157 | - iso639 = io.BytesIO(zf.read(isof)) | |
158 | + iso639 = open(os.path.join(mpath, 'calibre_iso639.mo'), 'rb') | |
159 | except: | |
160 | pass # No iso639 translations for this lang | |
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 |