]> git.pld-linux.org Git - packages/calibre.git/blob - calibre-locales.patch
6e6b41d9db32677eac697c387a9ab69f974b75f9
[packages/calibre.git] / calibre-locales.patch
1 --- calibre/src/calibre/utils/localization.py.old       2012-10-28 22:07:25.481983550 +0100
2 +++ calibre/src/calibre/utils/localization.py   2012-10-28 22:12:17.250402847 +0100
3 @@ -73,20 +73,20 @@ def get_lang():
4          lang = 'en'
5      return lang
6  
7 +def messages_path(lang):
8 +    return ('/usr/share/locale/%s/LC_MESSAGES'%lang)
9 +
10  def get_lc_messages_path(lang):
11      hlang = None
12 -    if zf_exists():
13 -        if lang in available_translations():
14 -            hlang = lang
15 -        else:
16 -            xlang = lang.split('_')[0].lower()
17 -            if xlang in available_translations():
18 -                hlang = xlang
19 -    return hlang
20 -
21 -def zf_exists():
22 -    return os.path.exists(P('localization/locales.zip',
23 -                allow_user_override=False))
24 +    if lang in available_translations():
25 +        hlang = lang
26 +    else:
27 +        xlang = lang.split('_')[0]
28 +        if xlang in available_translations():
29 +            hlang = xlang
30 +        if hlang is not None:
31 +            return messages_path(hlang)
32 +        return None
33  
34  def set_translators():
35      # To test different translations invoke as
36 @@ -110,18 +110,12 @@ def set_translators():
37                  buf = cStringIO.StringIO(buf.getvalue())
38  
39          if mpath is not None:
40 -            from zipfile import ZipFile
41 -            with ZipFile(P('localization/locales.zip',
42 -                allow_user_override=False), 'r') as zf:
43 -                if buf is None:
44 -                    buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
45 -                if mpath == 'nds':
46 -                    mpath = 'de'
47 -                isof = mpath + '/iso639.mo'
48 -                try:
49 -                    iso639 = cStringIO.StringIO(zf.read(isof))
50 -                except:
51 -                    pass # No iso639 translations for this lang
52 +            if buf is None:
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')
58  
59          if buf is not None:
60              t = GNUTranslations(buf)
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
63 @@ -5,10 +5,10 @@
64  __license__   = 'GPL v3'
65  __copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
66
67 +import os
68  import cStringIO
69  from gettext import GNUTranslations
70  from calibre.utils.localization import get_lc_messages_path
71 -from zipfile import ZipFile
72
73  __all__ = ['translate']
74
75 @@ -21,15 +21,10 @@
76      else:
77          mpath = get_lc_messages_path(lang)
78          if mpath is not None:
79 -            with ZipFile(P('localization/locales.zip',
80 -                allow_user_override=False), 'r') as zf:
81 -                try:
82 -                    buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
83 -                except:
84 -                    pass
85 -                else:
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
92      if trans is None:
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
97 @@ -131,7 +131,7 @@
98  
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')
103  
104      def run(self, opts):
105          for f in self.po_files():
106 @@ -139,8 +139,9 @@
107              base = os.path.dirname(dest)
108              if not os.path.exists(base):
109                  os.makedirs(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',
117                      '%s.po'%iscpo)
118 @@ -155,7 +156,6 @@
119                  self.warn('No ISO 639 translations for locale:', locale)
120  
121          self.write_stats()
122 -        self.freeze_locales()
123  
124      def check_iso639(self, path):
125          from calibre.utils.localization import langnames_to_langcodes
126 @@ -165,15 +166,6 @@
127                              os.path.basename(path), msgstr, msgid, rmap[msgstr]))
128                      # raise SystemExit(1)
129                  rmap[msgstr] = msgid
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):
This page took 0.049282 seconds and 2 git commands to generate.