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