]>
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 = [] | |
12 | @@ -152,8 +152,9 @@ class Translations(POT): # {{{ | |
13 | base = os.path.dirname(dest) | |
14 | if not os.path.exists(base): | |
15 | os.makedirs(base) | |
16 | - self.info('\tCompiling translations for', locale) | |
17 | - subprocess.check_call(['msgfmt', '-o', dest, f]) | |
18 | + if self.newer(dest, f): | |
19 | + self.info('\tCompiling translations for', locale) | |
20 | + subprocess.check_call(['msgfmt', '-o', dest, f]) | |
21 | iscpo = {'bn':'bn_IN', 'zh_HK':'zh_CN'}.get(locale, locale) | |
22 | iso639 = self.j(self.LP_ISO_PATH, '%s.po'%iscpo) | |
23 | ||
24 | @@ -174,7 +175,6 @@ class Translations(POT): # {{{ | |
25 | raise SystemExit(1) | |
26 | ||
27 | self.write_stats() | |
28 | - self.freeze_locales() | |
29 | ||
30 | def check_iso639(self, path): | |
31 | from calibre.utils.localization import langnames_to_langcodes | |
32 | @@ -198,15 +198,6 @@ class Translations(POT): # {{{ | |
33 | # raise SystemExit(1) | |
34 | rmap[msgstr] = msgid | |
35 | ||
36 | - def freeze_locales(self): | |
37 | - zf = self.DEST + '.zip' | |
38 | - from calibre import CurrentDir | |
39 | - from calibre.utils.zipfile import ZipFile, ZIP_DEFLATED | |
40 | - with ZipFile(zf, 'w', ZIP_DEFLATED) as zf: | |
41 | - with CurrentDir(self.DEST): | |
42 | - zf.add_dir('.') | |
43 | - shutil.rmtree(self.DEST) | |
44 | - | |
45 | @property | |
46 | def stats(self): | |
47 | return self.j(self.d(self.DEST), 'stats.pickle') | |
48 | --- calibre/src/calibre/translations/dynamic.py.wiget 2013-12-06 05:13:34.000000000 +0100 | |
49 | +++ calibre/src/calibre/translations/dynamic.py 2013-12-09 09:28:32.349958101 +0100 | |
50 | @@ -5,10 +5,10 @@ Dynamic language lookup of translations | |
51 | __license__ = 'GPL v3' | |
52 | __copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>' | |
53 | ||
54 | +import os | |
55 | import cStringIO | |
56 | from gettext import GNUTranslations | |
57 | from calibre.utils.localization import get_lc_messages_path | |
58 | -from zipfile import ZipFile | |
59 | ||
60 | __all__ = ['translate'] | |
61 | ||
62 | @@ -21,15 +21,10 @@ def translate(lang, text): | |
63 | else: | |
64 | mpath = get_lc_messages_path(lang) | |
65 | if mpath is not None: | |
66 | - with ZipFile(P('localization/locales.zip', | |
67 | - allow_user_override=False), 'r') as zf: | |
68 | - try: | |
69 | - buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo')) | |
70 | - except: | |
71 | - pass | |
72 | - else: | |
73 | - trans = GNUTranslations(buf) | |
74 | - _CACHE[lang] = trans | |
75 | + p = os.path.join(mpath, 'messages.mo') | |
76 | + if os.path.exists(p): | |
77 | + trans = GNUTranslations(open(p, 'rb')) | |
78 | + _CACHE[lang] = trans | |
79 | if trans is None: | |
80 | return getattr(__builtins__, '_', lambda x: x)(text) | |
81 | return trans.ugettext(text) | |
82 | --- calibre/src/calibre/utils/localization.py.wiget 2013-12-06 05:13:34.000000000 +0100 | |
83 | +++ calibre/src/calibre/utils/localization.py 2013-12-09 09:31:05.694326467 +0100 | |
84 | @@ -74,20 +74,20 @@ def get_lang(): | |
5cfefa9c | 85 | lang = 'en' |
86 | return lang | |
b65e37c7 | 87 | |
e69f76cd JK |
88 | +def messages_path(lang): |
89 | + return ('/usr/share/locale/%s/LC_MESSAGES'%lang) | |
5cfefa9c | 90 | + |
91 | def get_lc_messages_path(lang): | |
92 | hlang = None | |
93 | - if zf_exists(): | |
94 | - if lang in available_translations(): | |
95 | - hlang = lang | |
96 | - else: | |
591b7d3d | 97 | - xlang = lang.split('_')[0].lower() |
5cfefa9c | 98 | - if xlang in available_translations(): |
99 | - hlang = xlang | |
100 | - return hlang | |
101 | - | |
102 | -def zf_exists(): | |
103 | - return os.path.exists(P('localization/locales.zip', | |
104 | - allow_user_override=False)) | |
105 | + if lang in available_translations(): | |
106 | + hlang = lang | |
107 | + else: | |
108 | + xlang = lang.split('_')[0] | |
109 | + if xlang in available_translations(): | |
110 | + hlang = xlang | |
b65e37c7 | 111 | + if hlang is not None: |
112 | + return messages_path(hlang) | |
113 | + return None | |
114 | ||
2d44714a AF |
115 | _lang_trans = None |
116 | ||
117 | @@ -114,18 +114,12 @@ def set_translators(): | |
7f3c43c5 | 118 | buf = cStringIO.StringIO(buf.getvalue()) |
b65e37c7 | 119 | |
5cfefa9c | 120 | if mpath is not None: |
7f3c43c5 | 121 | - from zipfile import ZipFile |
5cfefa9c | 122 | - with ZipFile(P('localization/locales.zip', |
123 | - allow_user_override=False), 'r') as zf: | |
124 | - if buf is None: | |
125 | - buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo')) | |
126 | - if mpath == 'nds': | |
127 | - mpath = 'de' | |
128 | - isof = mpath + '/iso639.mo' | |
129 | - try: | |
130 | - iso639 = cStringIO.StringIO(zf.read(isof)) | |
131 | - except: | |
2d44714a | 132 | - pass # No iso639 translations for this lang |
5cfefa9c | 133 | + if buf is None: |
134 | + buf = open(os.path.join(mpath, 'calibre.mo'), 'rb') | |
135 | + mpath = mpath.replace(os.sep+'nds'+os.sep, os.sep+'de'+os.sep) | |
136 | + isof = os.path.join(mpath, 'calibre_iso639.mo') | |
b65e37c7 | 137 | + if os.path.exists(isof): |
5cfefa9c | 138 | + iso639 = open(isof, 'rb') |
b65e37c7 | 139 | |
5cfefa9c | 140 | if buf is not None: |
591b7d3d | 141 | t = GNUTranslations(buf) |