1 --- calibre/src/calibre/utils/localization.py~ 2012-01-13 05:32:13.000000000 +0100
2 +++ calibre/src/calibre/utils/localization.py 2012-01-17 09:35:01.311333439 +0100
7 + def messages_path(lang):
8 + return ('/usr/share/locale/%s/LC_MESSAGES'%lang)
10 def get_lc_messages_path(lang):
13 - if lang in available_translations():
16 - xlang = lang.split('_')[0]
17 - if xlang in available_translations():
22 - return os.path.exists(P('localization/locales.zip',
23 - allow_user_override=False))
24 + if lang in available_translations():
27 + xlang = lang.split('_')[0]
28 + if xlang in available_translations():
30 + if hlang is not None:
31 + return messages_path(hlang)
34 def set_translators():
35 # To test different translations invoke as
37 buf = cStringIO.StringIO(buf.getvalue())
40 - from zipfile import ZipFile
41 - with ZipFile(P('localization/locales.zip',
42 - allow_user_override=False), 'r') as zf:
44 - buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
47 - isof = mpath + '/iso639.mo'
49 - iso639 = cStringIO.StringIO(zf.read(isof))
51 - pass # No iso639 translations for this lang
53 + buf = open(os.path.join(mpath, 'calibre.mo'), 'rb')
54 + mpath = mpath.replace(os.sep+'nds'+os.sep, os.sep+'de'+os.sep)
55 + isof = os.path.join(mpath, 'calibre_iso639.mo')
56 + if os.path.exists(isof):
57 + iso639 = open(isof, 'rb')
61 --- calibre/src/calibre/translations/dynamic.py.orig 2012-01-13 05:32:13.000000000 +0100
62 +++ calibre/src/calibre/translations/dynamic.py 2012-01-17 09:37:53.594649557 +0100
64 __license__ = 'GPL v3'
65 __copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
69 from gettext import GNUTranslations
70 from calibre.utils.localization import get_lc_messages_path
71 -from zipfile import ZipFile
73 __all__ = ['translate']
77 mpath = get_lc_messages_path(lang)
79 - with ZipFile(P('localization/locales.zip',
80 - allow_user_override=False), 'r') as zf:
82 - buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
86 - trans = GNUTranslations(buf)
87 - _CACHE[lang] = trans
88 + p = os.path.join(mpath, 'messages.mo')
89 + if os.path.exists(p):
90 + trans = GNUTranslations(open(p, 'rb'))
91 + _CACHE[lang] = trans
93 return getattr(__builtins__, '_', lambda x: x)(text)
94 return trans.ugettext(text)
95 --- calibre/setup/translations.py.orig 2011-08-26 18:36:51.000000000 +0200
96 +++ calibre/setup/translations.py 2011-08-27 12:55:49.997229244 +0200
99 def mo_file(self, po_file):
100 locale = os.path.splitext(os.path.basename(po_file))[0]
101 - return locale, os.path.join(self.DEST, locale, 'messages.mo')
102 + return locale, os.path.join(self.DEST, locale, 'LC_MESSAGES', 'messages.mo')
105 for f in self.po_files():
107 base = os.path.dirname(dest)
108 if not os.path.exists(base):
110 - self.info('\tCompiling translations for', locale)
111 - subprocess.check_call(['msgfmt', '-o', dest, f])
112 + if self.newer(dest, f):
113 + self.info('\tCompiling translations for', locale)
114 + subprocess.check_call(['msgfmt', '-o', dest, f])
115 iscpo = {'bn':'bn_IN', 'zh_HK':'zh_CN'}.get(locale, locale)
116 iso639 = self.j(self.d(self.SRC), 'setup', 'iso_639',
119 self.warn('No ISO 639 translations for locale:', locale)
122 - self.freeze_locales()
124 - def freeze_locales(self):
125 - zf = self.DEST + '.zip'
126 - from calibre import CurrentDir
127 - from calibre.utils.zipfile import ZipFile, ZIP_DEFLATED
128 - with ZipFile(zf, 'w', ZIP_DEFLATED) as zf:
129 - with CurrentDir(self.DEST):
131 - shutil.rmtree(self.DEST)