]>
Commit | Line | Data |
---|---|---|
5cfefa9c | 1 | --- calibre/src/calibre/utils/localization.py~ 2011-06-24 20:01:27.000000000 +0200 |
2 | +++ calibre/src/calibre/utils/localization.py 2011-06-29 10:27:57.620747185 +0200 | |
3 | @@ -8,7 +8,6 @@ | |
4 | ||
5 | import os, locale, re, cStringIO, cPickle | |
6 | from gettext import GNUTranslations | |
7 | -from zipfile import ZipFile | |
8 | ||
9 | _available_translations = None | |
10 | ||
11 | @@ -50,20 +49,20 @@ | |
12 | lang = 'en' | |
13 | return lang | |
14 | ||
15 | +def messages_path(lang): | |
16 | + return ('/usr/share/locale/%s/LC_MESSAGES'%lang) | |
17 | + | |
18 | def get_lc_messages_path(lang): | |
19 | hlang = None | |
20 | - if zf_exists(): | |
21 | - if lang in available_translations(): | |
22 | - hlang = lang | |
23 | - else: | |
24 | - xlang = lang.split('_')[0] | |
25 | - if xlang in available_translations(): | |
26 | - hlang = xlang | |
27 | - return hlang | |
28 | - | |
29 | -def zf_exists(): | |
30 | - return os.path.exists(P('localization/locales.zip', | |
31 | - allow_user_override=False)) | |
32 | + if lang in available_translations(): | |
33 | + hlang = lang | |
34 | + else: | |
35 | + xlang = lang.split('_')[0] | |
36 | + if xlang in available_translations(): | |
37 | + hlang = xlang | |
38 | + if hlang is not None: | |
39 | + return messages_path(hlang) | |
40 | + return None | |
41 | ||
42 | def set_translators(): | |
43 | # To test different translations invoke as | |
44 | @@ -79,17 +78,12 @@ | |
45 | ||
46 | mpath = get_lc_messages_path(lang) | |
47 | if mpath is not None: | |
48 | - with ZipFile(P('localization/locales.zip', | |
49 | - allow_user_override=False), 'r') as zf: | |
50 | - if buf is None: | |
51 | - buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo')) | |
52 | - if mpath == 'nds': | |
53 | - mpath = 'de' | |
54 | - isof = mpath + '/iso639.mo' | |
55 | - try: | |
56 | - iso639 = cStringIO.StringIO(zf.read(isof)) | |
57 | - except: | |
58 | - pass # No iso639 translations for this lang | |
59 | + if buf is None: | |
60 | + buf = open(os.path.join(mpath, 'calibre.mo'), 'rb') | |
61 | + mpath = mpath.replace(os.sep+'nds'+os.sep, os.sep+'de'+os.sep) | |
62 | + isof = os.path.join(mpath, 'calibre_iso639.mo') | |
63 | + if os.path.exists(isof): | |
64 | + iso639 = open(isof, 'rb') | |
65 | ||
66 | if buf is not None: | |
67 | t = GNUTranslations(buf) | |
68 | --- calibre/src/calibre/translations/dynamic.py~ 2011-06-24 20:01:27.000000000 +0200 | |
69 | +++ calibre/src/calibre/translations/dynamic.py 2011-06-29 10:37:52.305747266 +0200 | |
70 | @@ -5,9 +5,10 @@ | |
71 | __license__ = 'GPL v3' | |
72 | __copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>' | |
73 | ||
74 | +import os | |
75 | import cStringIO | |
76 | from gettext import GNUTranslations | |
77 | -from calibre.utils.localization import get_lc_messages_path, ZipFile | |
78 | +from calibre.utils.localization import get_lc_messages_path | |
79 | ||
80 | __all__ = ['translate'] | |
81 | ||
82 | @@ -20,15 +21,10 @@ | |
83 | else: | |
84 | mpath = get_lc_messages_path(lang) | |
85 | if mpath is not None: | |
86 | - with ZipFile(P('localization/locales.zip', | |
87 | - allow_user_override=False), 'r') as zf: | |
88 | - try: | |
89 | - buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo')) | |
90 | - except: | |
91 | - pass | |
92 | - else: | |
93 | - trans = GNUTranslations(buf) | |
94 | - _CACHE[lang] = trans | |
95 | + p = os.path.join(mpath, 'messages.mo') | |
96 | + if os.path.exists(p): | |
97 | + trans = GNUTranslations(open(p, 'rb')) | |
98 | + _CACHE[lang] = trans | |
99 | if trans is None: | |
100 | return getattr(__builtins__, '_', lambda x: x)(text) | |
101 | return trans.ugettext(text) | |
102 | --- calibre/setup/translations.py~ 2011-06-24 20:01:27.000000000 +0200 | |
103 | +++ calibre/setup/translations.py 2011-06-29 10:47:26.808247162 +0200 | |
104 | @@ -85,7 +85,7 @@ | |
105 | ||
106 | def mo_file(self, po_file): | |
107 | locale = os.path.splitext(os.path.basename(po_file))[0] | |
108 | - return locale, os.path.join(self.DEST, locale, 'messages.mo') | |
109 | + return locale, os.path.join(self.DEST, locale, 'LC_MESSAGES', 'messages.mo') | |
110 | ||
111 | ||
112 | def run(self, opts): | |
113 | @@ -94,8 +94,9 @@ | |
114 | base = os.path.dirname(dest) | |
115 | if not os.path.exists(base): | |
116 | os.makedirs(base) | |
117 | - self.info('\tCompiling translations for', locale) | |
118 | - subprocess.check_call(['msgfmt', '-o', dest, f]) | |
119 | + if self.newer(dest, f): | |
120 | + self.info('\tCompiling translations for', locale) | |
121 | + subprocess.check_call(['msgfmt', '-o', dest, f]) | |
122 | if locale in ('en_GB', 'nds', 'te', 'yi'): | |
123 | continue | |
124 | pycountry = self.j(sysconfig.get_python_lib(), 'pycountry', | |
125 | @@ -122,16 +123,6 @@ | |
126 | shutil.copy2(f, dest) | |
127 | ||
128 | self.write_stats() | |
129 | - self.freeze_locales() | |
130 | - | |
131 | - def freeze_locales(self): | |
132 | - zf = self.DEST + '.zip' | |
133 | - from calibre import CurrentDir | |
134 | - from calibre.utils.zipfile import ZipFile, ZIP_DEFLATED | |
135 | - with ZipFile(zf, 'w', ZIP_DEFLATED) as zf: | |
136 | - with CurrentDir(self.DEST): | |
137 | - zf.add_dir('.') | |
138 | - shutil.rmtree(self.DEST) | |
139 | ||
140 | @property | |
141 | def stats(self): |