1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-04-20 05:03:35 +02:00

Removed gettext related functions

This commit is contained in:
2020-05-03 19:00:20 +02:00
parent 35445cb736
commit 212cb56d42
92 changed files with 1505 additions and 1605 deletions

View File

@@ -967,7 +967,7 @@ class Manifest(object):
if title:
title = str(title[0])
else:
title = _('Unknown')
title = 'Unknown'
return self._parse_xhtml(convert_markdown(data, title=title))
@@ -1368,23 +1368,23 @@ class Guide(object):
:attr:`href`: Book-internal URL of the referenced section. May include
a fragment identifier.
"""
_TYPES_TITLES = [('cover', __('Cover')),
('title-page', __('Title page')),
('toc', __('Table of Contents')),
('index', __('Index')),
('glossary', __('Glossary')),
('acknowledgements', __('Acknowledgements')),
('bibliography', __('Bibliography')),
('colophon', __('Colophon')),
('copyright-page', __('Copyright')),
('dedication', __('Dedication')),
('epigraph', __('Epigraph')),
('foreword', __('Foreword')),
('loi', __('List of illustrations')),
('lot', __('List of tables')),
('notes', __('Notes')),
('preface', __('Preface')),
('text', __('Main text'))]
_TYPES_TITLES = [('cover', 'Cover'),
('title-page', 'Title page'),
('toc', 'Table of Contents'),
('index', 'Index'),
('glossary', 'Glossary'),
('acknowledgements', 'Acknowledgements'),
('bibliography', 'Bibliography'),
('colophon', 'Colophon'),
('copyright-page', 'Copyright'),
('dedication', 'Dedication'),
('epigraph', 'Epigraph'),
('foreword', 'Foreword'),
('loi', 'List of illustrations'),
('lot', 'List of tables'),
('notes', 'Notes'),
('preface', 'Preface'),
('text', 'Main text')]
TITLES = dict(_TYPES_TITLES)
TYPES = frozenset(TITLES)
ORDER = {t: i for i, (t, _) in enumerate(_TYPES_TITLES)}

View File

@@ -312,14 +312,14 @@ def parse_html(data, log=None, decoder=None, preprocessor=None,
head = etree.Element(XHTML('head'))
data.insert(0, head)
title = etree.SubElement(head, XHTML('title'))
title.text = _('Unknown')
title.text = 'Unknown'
elif not xpath(data, '/h:html/h:head/h:title'):
title = etree.SubElement(head, XHTML('title'))
title.text = _('Unknown')
title.text = 'Unknown'
# Ensure <title> is not empty
title = xpath(data, '/h:html/h:head/h:title')[0]
if not title.text or not title.text.strip():
title.text = _('Unknown')
title.text = 'Unknown'
# Remove any encoding-specifying <meta/> elements
for meta in META_XP(data):
meta.getparent().remove(meta)

View File

@@ -1458,12 +1458,13 @@ class AZW3Container(Container):
with open(pathtoazw3, 'rb') as stream:
raw = stream.read(3)
if raw == b'TPZ':
raise InvalidMobi(_('This is not a MOBI file. It is a Topaz file.'))
raise InvalidMobi('This is not a MOBI file. It is a Topaz '
'file.')
try:
header = MetadataHeader(stream, default_log)
except MobiError:
raise InvalidMobi(_('This is not a MOBI file.'))
raise InvalidMobi('This is not a MOBI file.')
if header.encryption_type != 0:
raise DRMError()
@@ -1471,15 +1472,16 @@ class AZW3Container(Container):
kf8_type = header.kf8_type
if kf8_type is None:
raise InvalidMobi(_('This MOBI file does not contain a KF8 format '
'book. KF8 is the new format from Amazon. calibre can '
'only edit MOBI files that contain KF8 books. Older '
'MOBI files without KF8 are not editable.'))
raise InvalidMobi('This MOBI file does not contain a KF8 '
'format book. KF8 is the new format from '
'Amazon. calibre can only edit MOBI files '
'that contain KF8 books. Older MOBI files '
'without KF8 are not editable.')
if kf8_type == 'joint':
raise InvalidMobi(_('This MOBI file contains both KF8 and '
'older Mobi6 data. calibre can only edit MOBI files '
'that contain only KF8 data.'))
raise InvalidMobi('This MOBI file contains both KF8 and older '
'Mobi6 data. calibre can only edit MOBI '
'files that contain only KF8 data.')
try:
opf_path, obfuscated_fonts = fork_job(

View File

@@ -167,20 +167,19 @@ def remove_unused_css(container, report=None, remove_unused_classes=False, merge
num_changes = num_of_removed_rules + num_merged + num_of_removed_classes
if num_changes > 0:
if num_of_removed_rules > 0:
report(ngettext('Removed one unused CSS style rule', 'Removed {} unused CSS style rules',
num_of_removed_rules).format(num_of_removed_rules))
report('Removed {} unused CSS style '
'rules'.format(num_of_removed_rules))
if num_of_removed_classes > 0:
report(ngettext('Removed one unused class from the HTML', 'Removed {} unused classes from the HTML',
num_of_removed_classes).format(num_of_removed_classes))
report('Removed {} unused classes from the HTML'
.format(num_of_removed_classes))
if num_merged > 0:
report(ngettext('Merged one CSS style rule', 'Merged {} CSS style rules',
num_merged).format(num_merged))
report('Merged {} CSS style rules'.format(num_merged))
if num_of_removed_rules == 0:
report(_('No unused CSS style rules found'))
report('No unused CSS style rules found')
if remove_unused_classes and num_of_removed_classes == 0:
report(_('No unused class attributes found'))
report('No unused class attributes found')
if merge_rules and num_merged == 0:
report(_('No style rules that could be merged found'))
report('No style rules that could be merged found')
return num_changes > 0

View File

@@ -13,7 +13,8 @@ class InvalidBook(ValueError):
class DRMError(_DRMError):
def __init__(self):
super(DRMError, self).__init__(_('This file is locked with DRM. It cannot be edited.'))
super(DRMError, self).__init__('This file is locked with DRM. It '
'cannot be edited.')
class MalformedMarkup(ValueError):

View File

@@ -157,7 +157,7 @@ def smarten_punctuation(container, report):
newhtml = smarten_punctuation(html, container.log)
if newhtml != html:
changed = True
report(_('Smartened punctuation in: %s')%name)
report('Smartened punctuation in: %s' % name)
newhtml = strip_encoding_declarations(newhtml)
f.seek(0)
f.truncate()
@@ -171,7 +171,7 @@ def smarten_punctuation(container, report):
container.dirty(name)
smartened = True
if not smartened:
report(_('No punctuation that could be smartened found'))
report('No punctuation that could be smartened found')
return smartened

View File

@@ -194,8 +194,9 @@ def split(container, name, loc_or_xpath, before=True, totals=None):
try:
split_point = node_from_loc(root, loc_or_xpath, totals=totals)
except MalformedMarkup:
raise MalformedMarkup(_('The file %s has malformed markup. Try running the Fix HTML tool'
' before splitting') % name)
raise MalformedMarkup('The file %s has malformed markup. Try '
'running the Fix HTML tool before '
'splitting' % name)
container.replace(name, root)
if in_table(split_point):
raise AbortError('Cannot split inside tables')
@@ -269,7 +270,7 @@ def multisplit(container, name, xpath, before=True):
root = container.parsed(name)
nodes = root.xpath(xpath, namespaces=XPNSMAP)
if not nodes:
raise AbortError(_('The expression %s did not match any nodes') % xpath)
raise AbortError('The expression %s did not match any nodes' % xpath)
for split_point in nodes:
if in_table(split_point):
raise AbortError('Cannot split inside tables')

View File

@@ -240,17 +240,17 @@ def verify_toc_destinations(container, toc):
name = item.dest
if not name:
item.dest_exists = False
item.dest_error = _('No file named %s exists')%name
item.dest_error = 'No file named %s exists' % name
continue
try:
root = container.parsed(name)
except KeyError:
item.dest_exists = False
item.dest_error = _('No file named %s exists')%name
item.dest_error = 'No file named %s exists' % name
continue
if not hasattr(root, 'xpath'):
item.dest_exists = False
item.dest_error = _('No HTML file named %s exists')%name
item.dest_error = 'No HTML file named %s exists' % name
continue
if not item.frag:
item.dest_exists = True
@@ -259,9 +259,8 @@ def verify_toc_destinations(container, toc):
anchor_map[name] = frozenset(anchor_xpath(root))
item.dest_exists = item.frag in anchor_map[name]
if not item.dest_exists:
item.dest_error = _(
'The anchor %(a)s does not exist in file %(f)s')%dict(
a=item.frag, f=name)
item.dest_error = ('The anchor %(a)s does not exist in file '
'%(f)s' % dict(a=item.frag, f=name))
def find_existing_ncx_toc(container):
@@ -370,7 +369,7 @@ def elem_to_toc_text(elem):
text = re.sub(r'\s+', ' ', text.strip())
text = text[:1000].strip()
if not text:
text = _('(Untitled)')
text = '(Untitled)'
return text
@@ -533,8 +532,9 @@ def from_files(container):
text = find_text(body[0])
if not text:
text = name.rpartition('/')[-1]
if i == 0 and text.rpartition('.')[0].lower() in {'titlepage', 'cover'}:
text = _('Cover')
if i == 0 and text.rpartition('.')[0].lower() in {'titlepage',
'cover'}:
text = 'Cover'
toc.add(text, name)
return toc
@@ -563,8 +563,9 @@ def add_id(container, name, loc, totals=None):
try:
node = node_from_loc(root, loc, totals=totals)
except MalformedMarkup:
raise MalformedMarkup(_('The file %s has malformed markup. Try running the Fix HTML tool'
' before editing.') % name)
raise MalformedMarkup('The file %s has malformed markup. Try '
'running the Fix HTML tool before '
'editing.' % name)
container.replace(name, root)
if not node.get('id'):
@@ -641,7 +642,7 @@ def commit_ncx_toc(container, toc, lang=None, uid=None):
if m:
uid = xml2text(m[0])
title = _('Table of Contents')
title = 'Table of Contents'
m = container.opf_xpath('//dc:title')
if m:
x = xml2text(m[0]).strip()

View File

@@ -146,14 +146,14 @@ class OEBReader(object):
m.add('identifier', str(uuid.uuid4()), id='uuid_id', scheme='uuid')
self.oeb.uid = self.oeb.metadata.identifier[-1]
if not m.title:
m.add('title', self.oeb.translate(__('Unknown')))
m.add('title', self.oeb.translate('Unknown'))
has_aut = False
for x in m.creator:
if getattr(x, 'role', '').lower() in ('', 'aut'):
has_aut = True
break
if not has_aut:
m.add('creator', self.oeb.translate(__('Unknown')), role='aut')
m.add('creator', self.oeb.translate('Unknown'), role='aut')
def _manifest_prune_invalid(self):
'''

View File

@@ -10,7 +10,7 @@ __all__ = ['HTMLTOCAdder']
__license__ = 'GPL v3'
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
DEFAULT_TITLE = __('Table of Contents')
DEFAULT_TITLE = 'Table of Contents'
STYLE_CSS = {
'nested': """
@@ -52,9 +52,9 @@ class HTMLTOCAdder(object):
@classmethod
def config(cls, cfg):
group = cfg.add_group('htmltoc', _('HTML TOC generation options.'))
group = cfg.add_group('htmltoc', 'HTML TOC generation options.')
group('toc_title', ['--toc-title'], default=None,
help=_('Title for any generated in-line table of contents.'))
help='Title for any generated in-line table of contents.')
return cfg
@classmethod

View File

@@ -110,12 +110,12 @@ class Jacket(Base):
try:
title = str(self.oeb.metadata.title[0])
except:
title = _('Unknown')
title = 'Unknown'
try:
authors = list(map(str, self.oeb.metadata.creator))
except:
authors = [_('Unknown')]
authors = ['Unknown']
root = render_jacket(mi, self.opts.output_profile,
alt_title=title, alt_tags=tags, alt_authors=authors,
@@ -174,10 +174,11 @@ class Series(str):
def __new__(self, series, series_index):
if series and series_index is not None:
roman = _('{1} of <em>{0}</em>').format(
roman = '{1} of <em>{0}</em>'.format(
escape(series), escape(fmt_sidx(series_index, use_roman=True)))
combined = _('{1} of <em>{0}</em>').format(
escape(series), escape(fmt_sidx(series_index, use_roman=False)))
combined = '{1} of <em>{0}</em>'.format(
escape(series), escape(fmt_sidx(series_index,
use_roman=False)))
else:
combined = roman = escape(series or u'')
s = str.__new__(self, combined)
@@ -227,7 +228,7 @@ def postprocess_jacket(root, output_profile, has_data):
def render_jacket(mi, output_profile,
alt_title=_('Unknown'), alt_tags=[], alt_comments='',
alt_title='Unknown', alt_tags=[], alt_comments='',
alt_publisher='', rescale_fonts=False, alt_authors=None):
with open(pkg_resources.resource_filename('ebook_converter',
'data/jacket/stylesheet.css'),
@@ -244,7 +245,7 @@ def render_jacket(mi, output_profile,
try:
title_str = alt_title if mi.is_null('title') else mi.title
except:
title_str = _('Unknown')
title_str = 'Unknown'
title_str = escape(title_str)
title = '<span class="title">%s</span>' % title_str
@@ -275,7 +276,7 @@ def render_jacket(mi, output_profile,
orig = mi.authors
if mi.is_null('authors'):
mi.authors = list(alt_authors or (_('Unknown'),))
mi.authors = list(alt_authors or ('Unknown',))
try:
author = mi.format_authors()
except:
@@ -285,20 +286,25 @@ def render_jacket(mi, output_profile,
has_data = {}
def generate_html(comments):
args = dict(xmlns=XHTML_NS,
title_str=title_str,
css=css,
title=title,
author=author,
publisher=publisher,
pubdate_label=_('Published'), pubdate=pubdate,
series_label=_('Series'), series=series,
rating_label=_('Rating'), rating=rating,
tags_label=_('Tags'), tags=tags,
comments=comments,
footer='',
searchable_tags=' '.join(escape(t)+'ttt' for t in tags.tags_list),
)
args = {'author': author,
'comments': comments,
'css': css,
'footer': '',
'pubdate': pubdate,
'pubdate_label': 'Published',
'publisher': publisher,
'rating': rating,
'rating_label': 'Rating',
'searchable_tags': ' '.join(escape(t) + 'ttt'
for t in tags.tags_list),
'series': series,
'series_label': 'Series',
'tags': tags,
'tags_label': 'Tags',
'title': title,
'title_str': title_str,
'xmlns': XHTML_NS}
for key in mi.custom_field_keys():
m = mi.get_user_metadata(key, False) or {}
try:

View File

@@ -35,10 +35,9 @@ class SplitError(ValueError):
def __init__(self, path, root):
size = len(tostring(root))/1024.
ValueError.__init__(self,
_('Could not find reasonable point at which to split: '
'%(path)s Sub-tree size: %(size)d KB')%dict(
path=path, size=size))
ValueError.__init__(self, 'Could not find reasonable point at which '
'to split: %(path)s Sub-tree size: %(size)d KB' %
{'path': path, 'size': size})
class Split(object):

View File

@@ -100,7 +100,7 @@ class DetectStructure(object):
for node in self.oeb.toc.iter():
if not node.title or not node.title.strip():
node.title = _('Unnamed')
node.title = 'Unnamed'
if self.opts.start_reading_at:
self.detect_start_reading()
@@ -279,7 +279,7 @@ class DetectStructure(object):
node = self.oeb.toc.add(text, _href,
play_order=self.oeb.toc.next_play_order())
added[elem] = node
# node.add(_('Top'), _href)
# node.add('Top', _href)
if self.opts.level2_toc is not None and added:
level2_toc, level2_title = self.get_toc_parts_for_xpath(self.opts.level2_toc)

View File

@@ -29,13 +29,13 @@ class OEBWriter(object):
"""Add any book-writing options to the :class:`Config` object
:param:`cfg`.
"""
oeb = cfg.add_group('oeb', _('OPF/NCX/etc. generation options.'))
oeb = cfg.add_group('oeb', 'OPF/NCX/etc. generation options.')
versions = ['1.2', '2.0']
oeb('opf_version', ['--opf-version'], default='2.0', choices=versions,
help=_('OPF version to generate. Default is %default.'))
help='OPF version to generate. Default is %default.')
oeb('adobe_page_map', ['--adobe-page-map'], default=False,
help=_('Generate an Adobe "page-map" file if pagination '
'information is available.'))
help='Generate an Adobe "page-map" file if pagination '
'information is available.')
return cfg
@classmethod