]> git.pld-linux.org Git - packages/calibre.git/blob - calibre-locales.patch
- Up to 2.28.0.
[packages/calibre.git] / calibre-locales.patch
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,7 +152,8 @@ class Translations(POT):  # {{{
13              base = os.path.dirname(dest)
14              if not os.path.exists(base):
15                  os.makedirs(base)
16 -            jobs.append(['msgfmt', '-o', dest, f])
17 +            if self.newer(dest, f):
18 +                jobs.append(['msgfmt', '-o', dest, f])
19              iscpo = {'bn':'bn_IN', 'zh_HK':'zh_CN'}.get(locale, locale)
20              iso639 = self.j(self.LP_ISO_PATH, '%s.po'%iscpo)
21  
22 @@ -174,7 +175,6 @@ class Translations(POT):  # {{{
23              raise SystemExit(1)
24  
25          self.write_stats()
26 -        self.freeze_locales()
27          self.compile_user_manual_translations()
28  
29      def check_iso639(self, path):
30 @@ -198,15 +198,6 @@ class Translations(POT):  # {{{
31                      # raise SystemExit(1)
32                  rmap[msgstr] = msgid
33  
34 -    def freeze_locales(self):
35 -        zf = self.DEST + '.zip'
36 -        from calibre import CurrentDir
37 -        from calibre.utils.zipfile import ZipFile, ZIP_DEFLATED
38 -        with ZipFile(zf, 'w', ZIP_DEFLATED) as zf:
39 -            with CurrentDir(self.DEST):
40 -                zf.add_dir('.')
41 -        shutil.rmtree(self.DEST)
42 -
43      @property
44      def stats(self):
45          return self.j(self.d(self.DEST), 'stats.pickle')
46 --- calibre/src/calibre/translations/dynamic.py.wiget   2013-12-06 05:13:34.000000000 +0100
47 +++ calibre/src/calibre/translations/dynamic.py 2013-12-09 09:28:32.349958101 +0100
48 @@ -5,10 +5,10 @@ Dynamic language lookup of translations
49  __license__   = 'GPL v3'
50  __copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
51  
52 +import os
53  import cStringIO
54  from gettext import GNUTranslations
55  from calibre.utils.localization import get_lc_messages_path
56 -from zipfile import ZipFile
57  
58  __all__ = ['translate']
59  
60 @@ -21,15 +21,10 @@ def translate(lang, text):
61      else:
62          mpath = get_lc_messages_path(lang)
63          if mpath is not None:
64 -            with ZipFile(P('localization/locales.zip',
65 -                allow_user_override=False), 'r') as zf:
66 -                try:
67 -                    buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
68 -                except:
69 -                    pass
70 -                else:
71 -                    trans = GNUTranslations(buf)
72 -                    _CACHE[lang] = trans
73 +           p = os.path.join(mpath, 'calibre.mo')
74 +           if os.path.exists(p):
75 +               trans = GNUTranslations(open(p, 'rb'))
76 +               _CACHE[lang] = trans
77      if trans is None:
78          return getattr(__builtins__, '_', lambda x: x)(text)
79      return trans.ugettext(text)
80 --- calibre/src/calibre/utils/localization.py.wiget     2013-12-06 05:13:34.000000000 +0100
81 +++ calibre/src/calibre/utils/localization.py   2013-12-09 09:31:05.694326467 +0100
82 @@ -74,20 +74,20 @@ def get_lang():
83          lang = 'en'
84      return lang
85  
86 +def messages_path(lang):
87 +    return ('/usr/share/locale/%s/LC_MESSAGES'%lang)
88 +
89  def get_lc_messages_path(lang):
90      hlang = None
91 -    if zf_exists():
92 -        if lang in available_translations():
93 -            hlang = lang
94 -        else:
95 -            xlang = lang.split('_')[0].lower()
96 -            if xlang in available_translations():
97 -                hlang = xlang
98 -    return hlang
99 -
100 -def zf_exists():
101 -    return os.path.exists(P('localization/locales.zip',
102 -                allow_user_override=False))
103 +    if lang in available_translations():
104 +        hlang = lang
105 +    else:
106 +        xlang = lang.split('_')[0]
107 +        if xlang in available_translations():
108 +            hlang = xlang
109 +    if hlang is not None:
110 +        return messages_path(hlang)
111 +    return None
112  
113  _lang_trans = None
114  
115 @@ -99,13 +99,14 @@
116  _lang_trans = None
117  
118  def get_all_translators():
119 -    from zipfile import ZipFile
120 -    with ZipFile(P('localization/locales.zip', allow_user_override=False), 'r') as zf:
121 -        for lang in available_translations():
122 -            mpath = get_lc_messages_path(lang)
123 -            if mpath is not None:
124 -                buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
125 -                yield lang, GNUTranslations(buf)
126 +    for lang in available_translations():
127 +        mpath = get_lc_messages_path(lang)
128 +        if mpath is not None:
129 +            try:
130 +                buf = open(os.path.join(mpath, 'calibre.mo'), 'rb')
131 +                yield lang, GNUTranslations(buf)
132 +            except:
133 +                pass
134  
135  lcdata = {
136      u'abday': (u'Sun', u'Mon', u'Tue', u'Wed', u'Thu', u'Fri', u'Sat'),
137 @@ -145,21 +145,20 @@
138                  buf = cStringIO.StringIO(buf.getvalue())
139  
140          if mpath is not None:
141 -            from zipfile import ZipFile
142 -            with ZipFile(P('localization/locales.zip',
143 -                allow_user_override=False), 'r') as zf:
144 -                if buf is None:
145 -                    buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
146 +            if buf is None:
147 +                try:
148 +                    buf = open(os.path.join(mpath, 'calibre.mo'), 'rb')
149 +                except:
150 +                    pass  # No translations for this lang
151                  if mpath == 'nds':
152                      mpath = 'de'
153 -                isof = mpath + '/iso639.mo'
154                  try:
155 -                    iso639 = cStringIO.StringIO(zf.read(isof))
156 +                    iso639 = open(os.path.join(mpath, 'calibre_iso639.mo'), 'rb')
157                  except:
158                      pass  # No iso639 translations for this lang
159                  if buf is not None:
160                      try:
161 -                        lcdata = cPickle.loads(zf.read(mpath + '/lcdata.pickle'))
162 +                        lcdata = cPickle.loads(open(os.path.join(mpath, 'calibre_lcdata.pickle')))
163                      except:
164                          pass  # No lcdata
165  
This page took 0.653406 seconds and 3 git commands to generate.