Ejemplo n.º 1
0
 def compile_content_server_translations(self):
     self.info('Compiling content-server translations')
     from calibre.utils.rapydscript import msgfmt
     from calibre.utils.zipfile import ZipFile, ZIP_DEFLATED, ZipInfo, ZIP_STORED
     with ZipFile(self.j(self.RESOURCES, 'content-server', 'locales.zip'), 'w', ZIP_DEFLATED) as zf:
         for src in glob.glob(os.path.join(self.TRANSLATIONS, 'content-server', '*.po')):
             data, h = self.hash_and_data(src)
             current_hash = h.digest()
             saved_hash, saved_data = self.read_cache(src)
             if current_hash == saved_hash:
                 raw = saved_data
             else:
                 # self.info('\tParsing ' + os.path.basename(src))
                 raw = None
                 po_data = data.decode('utf-8')
                 data = json.loads(msgfmt(po_data))
                 translated_entries = {k:v for k, v in iteritems(data['entries']) if v and sum(map(len, v))}
                 data[u'entries'] = translated_entries
                 data[u'hash'] = h.hexdigest()
                 cdata = b'{}'
                 if translated_entries:
                     raw = json.dumps(data, ensure_ascii=False, sort_keys=True)
                     if isinstance(raw, type(u'')):
                         raw = raw.encode('utf-8')
                     cdata = raw
                 self.write_cache(cdata, current_hash, src)
             if raw:
                 zi = ZipInfo(os.path.basename(src).rpartition('.')[0])
                 zi.compress_type = ZIP_STORED if is_ci else ZIP_DEFLATED
                 zf.writestr(zi, raw)
Ejemplo n.º 2
0
 def compile_content_server_translations(self):
     self.info('Compiling content-server translations')
     from calibre.utils.rapydscript import msgfmt
     from calibre.utils.zipfile import ZipFile, ZIP_DEFLATED, ZipInfo, ZIP_STORED
     with ZipFile(self.j(self.RESOURCES, 'content-server', 'locales.zip'), 'w', ZIP_DEFLATED) as zf:
         for src in glob.glob(os.path.join(self.TRANSLATIONS, 'content-server', '*.po')):
             data, h = self.hash_and_data(src)
             current_hash = h.digest()
             saved_hash, saved_data = self.read_cache(src)
             if current_hash == saved_hash:
                 raw = saved_data
             else:
                 self.info('\tParsing ' + os.path.basename(src))
                 raw = None
                 po_data = data.decode('utf-8')
                 data = json.loads(msgfmt(po_data))
                 translated_entries = {k:v for k, v in iteritems(data['entries']) if v and sum(map(len, v))}
                 data[u'entries'] = translated_entries
                 data[u'hash'] = h.hexdigest()
                 cdata = b'{}'
                 if translated_entries:
                     raw = json.dumps(data, ensure_ascii=False, sort_keys=True)
                     if isinstance(raw, type(u'')):
                         raw = raw.encode('utf-8')
                     cdata = raw
                 self.write_cache(cdata, current_hash, src)
             if raw:
                 zi = ZipInfo(os.path.basename(src).rpartition('.')[0])
                 zi.compress_type = ZIP_STORED if is_ci else ZIP_DEFLATED
                 zf.writestr(zi, raw)
Ejemplo n.º 3
0
 def compile_content_server_translations(self):
     self.info('\nCompiling content-server translations')
     from calibre.utils.rapydscript import msgfmt
     from calibre.utils.zipfile import ZipFile, ZIP_DEFLATED, ZipInfo
     with ZipFile(self.j(self.RESOURCES, 'content-server', 'locales.zip'), 'w', ZIP_DEFLATED) as zf:
         for src in glob.glob(os.path.join(self.TRANSLATIONS, 'content-server', '*.po')):
             with open(src, 'rb') as f:
                 po_data = f.read().decode('utf-8')
             data = json.loads(msgfmt(po_data))
             translated_entries = {k:v for k, v in data['entries'].iteritems() if v and sum(map(len, v))}
             data['entries'] = translated_entries
             if translated_entries:
                 raw = json.dumps(data, ensure_ascii=False, sort_keys=True)
                 if isinstance(raw, type(u'')):
                     raw = raw.encode('utf-8')
                 zi = ZipInfo(os.path.basename(src).rpartition('.')[0])
                 zi.compress_type = ZIP_DEFLATED
                 zf.writestr(zi, raw)
Ejemplo n.º 4
0
 def compile_content_server_translations(self):
     self.info('\nCompiling content-server translations')
     from calibre.utils.rapydscript import msgfmt
     from calibre.utils.zipfile import ZipFile, ZIP_DEFLATED, ZipInfo
     with ZipFile(self.j(self.RESOURCES, 'content-server', 'locales.zip'),
                  'w', ZIP_DEFLATED) as zf:
         for src in glob.glob(
                 os.path.join(self.TRANSLATIONS, 'content-server', '*.po')):
             with open(src, 'rb') as f:
                 po_data = f.read().decode('utf-8')
             data = json.loads(msgfmt(po_data))
             translated_entries = {
                 k: v
                 for k, v in data['entries'].iteritems()
                 if v and sum(map(len, v))
             }
             data['entries'] = translated_entries
             if translated_entries:
                 raw = json.dumps(data, ensure_ascii=False, sort_keys=True)
                 if isinstance(raw, type(u'')):
                     raw = raw.encode('utf-8')
                 zi = ZipInfo(os.path.basename(src).rpartition('.')[0])
                 zi.compress_type = ZIP_DEFLATED
                 zf.writestr(zi, raw)