]>
Commit | Line | Data |
---|---|---|
b0e4d610 | 1 | --- calibre/src/calibre/utils/localization.py.orig 2011-07-15 18:54:35.000000000 +0200 |
2 | +++ calibre/src/calibre/utils/localization.py 2011-07-18 13:53:51.356353825 +0200 | |
5cfefa9c | 3 | @@ -8,7 +8,6 @@ |
b0e4d610 | 4 | |
5cfefa9c | 5 | import os, locale, re, cStringIO, cPickle |
b0e4d610 | 6 | from gettext import GNUTranslations, NullTranslations |
5cfefa9c | 7 | -from zipfile import ZipFile |
b0e4d610 | 8 | |
5cfefa9c | 9 | _available_translations = None |
b0e4d610 | 10 | |
5cfefa9c | 11 | @@ -50,20 +49,20 @@ |
12 | lang = 'en' | |
13 | return lang | |
b0e4d610 | 14 | |
5cfefa9c | 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 | |
b0e4d610 | 41 | |
5cfefa9c | 42 | def set_translators(): |
43 | # To test different translations invoke as | |
44 | @@ -79,17 +78,12 @@ | |
b0e4d610 | 45 | |
5cfefa9c | 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') | |
b0e4d610 | 65 | |
66 | t = None | |
5cfefa9c | 67 | if buf is not None: |
5cfefa9c | 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) | |
e060118c | 102 | --- calibre/setup/translations.py.orig 2011-08-26 18:36:51.000000000 +0200 |
103 | +++ calibre/setup/translations.py 2011-08-27 12:55:49.997229244 +0200 | |
104 | @@ -131,7 +131,7 @@ | |
5cfefa9c | 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 | ||
5cfefa9c | 111 | def run(self, opts): |
b0e4d610 | 112 | for f in self.po_files(): |
e060118c | 113 | @@ -139,8 +139,9 @@ |
5cfefa9c | 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]) | |
e060118c | 122 | iscpo = {'bn':'bn_IN', 'zh_HK':'zh_CN'}.get(locale, locale) |
123 | iso639 = self.j(self.d(self.SRC), 'setup', 'iso_639', | |
124 | '%s.po'%iscpo) | |
125 | @@ -155,16 +156,6 @@ | |
126 | self.warn('No ISO 639 translations for locale:', locale) | |
5cfefa9c | 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): |