mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-20 21:21:35 +02:00
Removed gettext related functions
This commit is contained in:
@@ -32,7 +32,7 @@ class EXTHHeader(object): # {{{
|
||||
self.length, self.num_items = struct.unpack('>LL', raw[4:12])
|
||||
raw = raw[12:]
|
||||
pos = 0
|
||||
self.mi = MetaInformation(_('Unknown'), [_('Unknown')])
|
||||
self.mi = MetaInformation('Unknown', ['Unknown'])
|
||||
self.has_fake_cover = True
|
||||
self.start_offset = None
|
||||
left = self.num_items
|
||||
@@ -67,7 +67,7 @@ class EXTHHeader(object): # {{{
|
||||
if content == b'EBSP':
|
||||
if not self.mi.tags:
|
||||
self.mi.tags = []
|
||||
self.mi.tags.append(_('Sample Book'))
|
||||
self.mi.tags.append('Sample Book')
|
||||
elif idx == 502:
|
||||
# last update time
|
||||
pass
|
||||
@@ -127,7 +127,7 @@ class EXTHHeader(object): # {{{
|
||||
self.mi.authors.append(au)
|
||||
elif idx == 101:
|
||||
self.mi.publisher = clean_xml_chars(self.decode(content).strip())
|
||||
if self.mi.publisher in {'Unknown', _('Unknown')}:
|
||||
if self.mi.publisher in {'Unknown', 'Unknown'}:
|
||||
self.mi.publisher = None
|
||||
elif idx == 103:
|
||||
self.mi.comments = clean_xml_chars(self.decode(content).strip())
|
||||
@@ -194,7 +194,7 @@ class BookHeader(object):
|
||||
if len(raw) <= 16:
|
||||
self.codec = 'cp1252'
|
||||
self.extra_flags = 0
|
||||
self.title = _('Unknown')
|
||||
self.title = 'Unknown'
|
||||
self.language = 'ENGLISH'
|
||||
self.sublanguage = 'NEUTRAL'
|
||||
self.exth_flag, self.exth = 0, None
|
||||
@@ -233,7 +233,7 @@ class BookHeader(object):
|
||||
|
||||
toff, tlen = struct.unpack('>II', raw[0x54:0x5c])
|
||||
tend = toff + tlen
|
||||
self.title = raw[toff:tend] if tend < len(raw) else _('Unknown')
|
||||
self.title = raw[toff:tend] if tend < len(raw) else 'Unknown'
|
||||
langcode = struct.unpack('!L', raw[0x5C:0x60])[0]
|
||||
langid = langcode & 0xFF
|
||||
sublangid = (langcode >> 10) & 0xFF
|
||||
|
||||
@@ -30,10 +30,10 @@ class TopazError(ValueError):
|
||||
class KFXError(ValueError):
|
||||
|
||||
def __init__(self):
|
||||
ValueError.__init__(self, _(
|
||||
'This is an Amazon KFX book. It cannot be processed.'
|
||||
' See {} for information on how to handle KFX books.'
|
||||
).format('https://www.mobileread.com/forums/showthread.php?t=283371'))
|
||||
ValueError.__init__(self, 'This is an Amazon KFX book. It cannot be '
|
||||
'processed. See https://www.mobileread.com/forums/'
|
||||
'showthread.php?t=283371 for information on how '
|
||||
'to handle KFX books.')
|
||||
|
||||
|
||||
class MobiReader(object):
|
||||
@@ -77,7 +77,8 @@ class MobiReader(object):
|
||||
|
||||
raw = stream.read()
|
||||
if raw.startswith(b'TPZ'):
|
||||
raise TopazError(_('This is an Amazon Topaz book. It cannot be processed.'))
|
||||
raise TopazError('This is an Amazon Topaz book. It cannot be '
|
||||
'processed.')
|
||||
if raw.startswith(b'\xeaDRMION\xee'):
|
||||
raise KFXError()
|
||||
|
||||
@@ -642,7 +643,7 @@ class MobiReader(object):
|
||||
def create_opf(self, htmlfile, guide=None, root=None):
|
||||
mi = getattr(self.book_header.exth, 'mi', self.embedded_mi)
|
||||
if mi is None:
|
||||
mi = MetaInformation(self.book_header.title, [_('Unknown')])
|
||||
mi = MetaInformation(self.book_header.title, ['Unknown'])
|
||||
opf = OPFCreator(os.path.dirname(htmlfile), mi)
|
||||
if hasattr(self.book_header.exth, 'cover_offset'):
|
||||
opf.cover = 'images/%05d.jpg' % (self.book_header.exth.cover_offset + 1)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import os, glob
|
||||
import glob
|
||||
import os
|
||||
|
||||
from ebook_converter import CurrentDir
|
||||
from ebook_converter.ebooks.mobi import MobiError
|
||||
@@ -8,8 +9,8 @@ from ebook_converter.utils.logging import default_log
|
||||
from ebook_converter.ebooks import DRMError
|
||||
from ebook_converter.ebooks.mobi.reader.mobi8 import Mobi8Reader
|
||||
from ebook_converter.ebooks.conversion.plumber import Plumber, create_oebbook
|
||||
from ebook_converter.customize.ui import (plugin_for_input_format,
|
||||
plugin_for_output_format)
|
||||
from ebook_converter.customize.ui import plugin_for_input_format
|
||||
from ebook_converter.customize.ui import plugin_for_output_format
|
||||
from ebook_converter.utils.ipc.simple_worker import fork_job
|
||||
|
||||
|
||||
@@ -31,44 +32,46 @@ def do_explode(path, dest):
|
||||
opf = os.path.abspath(mr())
|
||||
try:
|
||||
os.remove('debug-raw.html')
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return opf
|
||||
|
||||
|
||||
def explode(path, dest, question=lambda x:True):
|
||||
def explode(path, dest, question=lambda x: True):
|
||||
with open(path, 'rb') as stream:
|
||||
raw = stream.read(3)
|
||||
stream.seek(0)
|
||||
if raw == b'TPZ':
|
||||
raise BadFormat(_('This is not a MOBI file. It is a Topaz file.'))
|
||||
raise BadFormat('This is not a MOBI file. It is a Topaz file.')
|
||||
|
||||
try:
|
||||
header = MetadataHeader(stream, default_log)
|
||||
except MobiError:
|
||||
raise BadFormat(_('This is not a MOBI file.'))
|
||||
raise BadFormat('This is not a MOBI file.')
|
||||
|
||||
if header.encryption_type != 0:
|
||||
raise DRMError(_('This file is locked with DRM. It cannot be tweaked.'))
|
||||
raise DRMError('This file is locked with DRM. It cannot be '
|
||||
'tweaked.')
|
||||
|
||||
kf8_type = header.kf8_type
|
||||
|
||||
if kf8_type is None:
|
||||
raise BadFormat(_('This MOBI file does not contain a KF8 format '
|
||||
'book. KF8 is the new format from Amazon. calibre can '
|
||||
'only tweak MOBI files that contain KF8 books. Older '
|
||||
'MOBI files without KF8 are not tweakable.'))
|
||||
raise BadFormat('This MOBI file does not contain a KF8 format '
|
||||
'book. KF8 is the new format from Amazon. calibre '
|
||||
'can only tweak MOBI files that contain KF8 '
|
||||
'books. Older MOBI files without KF8 are not '
|
||||
'tweakable.')
|
||||
|
||||
if kf8_type == 'joint':
|
||||
if not question(_('This MOBI file contains both KF8 and '
|
||||
'older Mobi6 data. Tweaking it will remove the Mobi6 data, which '
|
||||
'means the file will not be usable on older Kindles. Are you '
|
||||
'sure?')):
|
||||
if not question('This MOBI file contains both KF8 and older Mobi6 '
|
||||
'data. Tweaking it will remove the Mobi6 data, '
|
||||
'which means the file will not be usable on older '
|
||||
'Kindles. Are you sure?'):
|
||||
return None
|
||||
|
||||
return fork_job('ebook_converter.ebooks.mobi.tweak', 'do_explode', args=(path,
|
||||
dest), no_output=True)['result']
|
||||
return fork_job('ebook_converter.ebooks.mobi.tweak', 'do_explode',
|
||||
args=(path, dest), no_output=True)['result']
|
||||
|
||||
|
||||
def set_cover(oeb):
|
||||
@@ -96,11 +99,10 @@ def do_rebuild(opf, dest_path):
|
||||
def rebuild(src_dir, dest_path):
|
||||
opf = glob.glob(os.path.join(src_dir, '*.opf'))
|
||||
if not opf:
|
||||
raise ValueError('No OPF file found in %s'%src_dir)
|
||||
raise ValueError('No OPF file found in %s' % src_dir)
|
||||
opf = opf[0]
|
||||
# For debugging, uncomment the following two lines
|
||||
# def fork_job(a, b, args=None, no_output=True):
|
||||
# do_rebuild(*args)
|
||||
fork_job('ebook_converter.ebooks.mobi.tweak', 'do_rebuild', args=(opf, dest_path),
|
||||
no_output=True)
|
||||
|
||||
fork_job('ebook_converter.ebooks.mobi.tweak', 'do_rebuild',
|
||||
args=(opf, dest_path), no_output=True)
|
||||
|
||||
@@ -336,7 +336,7 @@ def utf8_text(text):
|
||||
text = text.decode('utf-8', 'replace')
|
||||
text = normalize(text).encode('utf-8')
|
||||
else:
|
||||
text = _('Unknown').encode('utf-8')
|
||||
text = 'Unknown'.encode('utf-8')
|
||||
return text
|
||||
|
||||
|
||||
|
||||
@@ -461,9 +461,9 @@ class Indexer(object): # {{{
|
||||
if node.klass == 'article':
|
||||
aut, desc = node.author, node.description
|
||||
if not aut:
|
||||
aut = _('Unknown')
|
||||
aut = 'Unknown'
|
||||
if not desc:
|
||||
desc = _('No details available')
|
||||
desc = 'No details available'
|
||||
node.author, node.description = aut, desc
|
||||
|
||||
self.cncx = CNCX(oeb.toc, self.is_periodical)
|
||||
|
||||
Reference in New Issue
Block a user