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
5 import os, locale, re, cStringIO, cPickle
6 from gettext import GNUTranslations
7 -from zipfile import ZipFile
9 _available_translations = None
15 +def messages_path(lang):
16 + return ('/usr/share/locale/%s/LC_MESSAGES'%lang)
18 def get_lc_messages_path(lang):
21 - if lang in available_translations():
24 - xlang = lang.split('_')[0]
25 - if xlang in available_translations():
30 - return os.path.exists(P('localization/locales.zip',
31 - allow_user_override=False))
32 + if lang in available_translations():
35 + xlang = lang.split('_')[0]
36 + if xlang in available_translations():
38 + if hlang is not None:
39 + return messages_path(hlang)
42 def set_translators():
43 # To test different translations invoke as
46 mpath = get_lc_messages_path(lang)
48 - with ZipFile(P('localization/locales.zip',
49 - allow_user_override=False), 'r') as zf:
51 - buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
54 - isof = mpath + '/iso639.mo'
56 - iso639 = cStringIO.StringIO(zf.read(isof))
58 - pass # No iso639 translations for this lang
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')
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
71 __license__ = 'GPL v3'
72 __copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
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
80 __all__ = ['translate']
84 mpath = get_lc_messages_path(lang)
86 - with ZipFile(P('localization/locales.zip',
87 - allow_user_override=False), 'r') as zf:
89 - buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
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
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
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')
114 base = os.path.dirname(dest)
115 if not os.path.exists(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'):
124 pycountry = self.j(sysconfig.get_python_lib(), 'pycountry',
126 shutil.copy2(f, dest)
129 - self.freeze_locales()
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):
138 - shutil.rmtree(self.DEST)