mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-19 12:43:35 +02:00
Removed gettext related functions
This commit is contained in:
@@ -344,9 +344,9 @@ class ResourceCollection(object):
|
||||
res.set_basedir(path)
|
||||
|
||||
|
||||
def MetaInformation(title, authors=(_('Unknown'),)):
|
||||
def MetaInformation(title, authors=('Unknown',)):
|
||||
''' Convenient encapsulation of book metadata, needed for compatibility
|
||||
@param title: title or ``_('Unknown')`` or a MetaInformation object
|
||||
@param title: title or ``'Unknown'`` or a MetaInformation object
|
||||
@param authors: List of strings or []
|
||||
'''
|
||||
from ebook_converter.ebooks.metadata.book.base import Metadata
|
||||
|
||||
@@ -40,8 +40,9 @@ class KPFExtract(FileTypePlugin):
|
||||
|
||||
name = 'KPF Extract'
|
||||
author = 'Kovid Goyal'
|
||||
description = _('Extract the source DOCX file from Amazon Kindle Create KPF files.'
|
||||
' Note this will not contain any edits made in the Kindle Create program itself.')
|
||||
description = ('Extract the source DOCX file from Amazon Kindle Create '
|
||||
'KPF files. Note this will not contain any edits made in '
|
||||
'the Kindle Create program itself.')
|
||||
file_types = {'kpf'}
|
||||
supported_platforms = ['windows', 'osx', 'linux']
|
||||
on_import = True
|
||||
@@ -62,9 +63,9 @@ class KPFExtract(FileTypePlugin):
|
||||
class ArchiveExtract(FileTypePlugin):
|
||||
name = 'Archive Extract'
|
||||
author = 'Kovid Goyal'
|
||||
description = _('Extract common e-book formats from archive files '
|
||||
'(ZIP/RAR). Also try to autodetect if they are actually '
|
||||
'CBZ/CBR files.')
|
||||
description = ('Extract common e-book formats from archive files (ZIP/'
|
||||
'RAR). Also try to autodetect if they are actually CBZ/CBR '
|
||||
'files.')
|
||||
file_types = {'zip', 'rar'}
|
||||
supported_platforms = ['windows', 'osx', 'linux']
|
||||
on_import = True
|
||||
|
||||
@@ -21,11 +21,11 @@ TOP_LEVEL_IDENTIFIERS = frozenset((
|
||||
))
|
||||
|
||||
PUBLICATION_METADATA_FIELDS = frozenset((
|
||||
'title', # title must never be None. Should be _('Unknown')
|
||||
'title', # title must never be None. Should be 'Unknown'
|
||||
# Pseudo field that can be set, but if not set is auto generated
|
||||
# from title and languages
|
||||
'title_sort',
|
||||
'authors', # Ordered list. Must never be None, can be [_('Unknown')]
|
||||
'authors', # Ordered list. Must never be None, can be ['Unknown']
|
||||
'author_sort_map', # Map of sort strings for each author
|
||||
# Pseudo field that can be set, but if not set is auto generated
|
||||
# from authors and languages
|
||||
|
||||
@@ -24,21 +24,19 @@ def human_readable(size, precision=2):
|
||||
return ('%.'+str(precision)+'f'+ 'MB') % (size/(1024*1024),)
|
||||
|
||||
|
||||
NULL_VALUES = {
|
||||
'user_metadata': {},
|
||||
'cover_data' : (None, None),
|
||||
'tags' : [],
|
||||
'identifiers' : {},
|
||||
'languages' : [],
|
||||
'device_collections': [],
|
||||
'author_sort_map': {},
|
||||
'authors' : [_('Unknown')],
|
||||
'author_sort' : _('Unknown'),
|
||||
'title' : _('Unknown'),
|
||||
'user_categories' : {},
|
||||
'author_link_map' : {},
|
||||
'language' : 'und'
|
||||
}
|
||||
NULL_VALUES = {'user_metadata': {},
|
||||
'cover_data': (None, None),
|
||||
'tags': [],
|
||||
'identifiers': {},
|
||||
'languages': [],
|
||||
'device_collections': [],
|
||||
'author_sort_map': {},
|
||||
'authors': ['Unknown'],
|
||||
'author_sort': 'Unknown',
|
||||
'title': 'Unknown',
|
||||
'user_categories': {},
|
||||
'author_link_map': {},
|
||||
'language': 'und'}
|
||||
|
||||
field_metadata = FieldMetadata()
|
||||
|
||||
@@ -74,10 +72,10 @@ class Metadata(object):
|
||||
'''
|
||||
__calibre_serializable__ = True
|
||||
|
||||
def __init__(self, title, authors=(_('Unknown'),), other=None, template_cache=None,
|
||||
formatter=None):
|
||||
def __init__(self, title, authors=('Unknown',), other=None,
|
||||
template_cache=None, formatter=None):
|
||||
'''
|
||||
@param title: title or ``_('Unknown')``
|
||||
@param title: title or ``'Unknown'``
|
||||
@param authors: List of strings or []
|
||||
@param other: None or a metadata object
|
||||
'''
|
||||
@@ -101,7 +99,7 @@ class Metadata(object):
|
||||
'''
|
||||
Return True if the value of field is null in this object.
|
||||
'null' means it is unknown or evaluates to False. So a title of
|
||||
_('Unknown') is null or a language of 'und' is null.
|
||||
'Unknown' is null or a language of 'und' is null.
|
||||
|
||||
Be careful with numeric fields since this will return True for zero as
|
||||
well as None.
|
||||
@@ -142,11 +140,9 @@ class Metadata(object):
|
||||
if val is None:
|
||||
d['#value#'] = 'RECURSIVE_COMPOSITE FIELD (Metadata) ' + field
|
||||
val = d['#value#'] = self.formatter.safe_format(
|
||||
d['display']['composite_template'],
|
||||
self,
|
||||
_('TEMPLATE ERROR'),
|
||||
self, column_name=field,
|
||||
template_cache=self.template_cache).strip()
|
||||
d['display']['composite_template'], self, 'TEMPLATE ERROR',
|
||||
self, column_name=field,
|
||||
template_cache=self.template_cache).strip()
|
||||
return val
|
||||
if field.startswith('#') and field.endswith('_index'):
|
||||
try:
|
||||
@@ -474,7 +470,7 @@ class Metadata(object):
|
||||
if v not in (None, NULL_VALUES.get(attr, None)):
|
||||
setattr(dest, attr, copy.deepcopy(v))
|
||||
|
||||
unknown = _('Unknown')
|
||||
unknown = 'Unknown'
|
||||
if other.title and other.title != unknown:
|
||||
self.title = other.title
|
||||
if hasattr(other, 'title_sort'):
|
||||
@@ -658,7 +654,7 @@ class Metadata(object):
|
||||
elif datatype == 'datetime':
|
||||
res = format_date(res, cmeta['display'].get('date_format','dd MMM yyyy'))
|
||||
elif datatype == 'bool':
|
||||
res = _('Yes') if res else _('No')
|
||||
res = 'Yes' if res else 'No'
|
||||
elif datatype == 'rating':
|
||||
res = '%.2g'%(res/2)
|
||||
elif datatype in ['int', 'float']:
|
||||
@@ -725,7 +721,7 @@ class Metadata(object):
|
||||
if self.authors:
|
||||
fmt('Author(s)', authors_to_string(self.authors) +
|
||||
((' [' + self.author_sort + ']')
|
||||
if self.author_sort and self.author_sort != _('Unknown') else ''))
|
||||
if self.author_sort and self.author_sort != 'Unknown' else ''))
|
||||
if self.publisher:
|
||||
fmt('Publisher', self.publisher)
|
||||
if getattr(self, 'book_producer', False):
|
||||
@@ -764,22 +760,26 @@ class Metadata(object):
|
||||
'''
|
||||
from ebook_converter.ebooks.metadata import authors_to_string
|
||||
from ebook_converter.utils.date import isoformat
|
||||
ans = [(_('Title'), str(self.title))]
|
||||
ans += [(_('Author(s)'), (authors_to_string(self.authors) if self.authors else _('Unknown')))]
|
||||
ans += [(_('Publisher'), str(self.publisher))]
|
||||
ans += [(_('Producer'), str(self.book_producer))]
|
||||
ans += [(_('Comments'), str(self.comments))]
|
||||
ans = [('Title', str(self.title))]
|
||||
ans += [('Author(s)', (authors_to_string(self.authors)
|
||||
if self.authors else 'Unknown'))]
|
||||
ans += [('Publisher', str(self.publisher))]
|
||||
ans += [('Producer', str(self.book_producer))]
|
||||
ans += [('Comments', str(self.comments))]
|
||||
ans += [('ISBN', str(self.isbn))]
|
||||
ans += [(_('Tags'), ', '.join([str(t) for t in self.tags]))]
|
||||
ans += [('Tags', ', '.join([str(t) for t in self.tags]))]
|
||||
if self.series:
|
||||
ans += [(_('Series'), str(self.series) + ' #%s'%self.format_series_index())]
|
||||
ans += [(_('Languages'), ', '.join(self.languages))]
|
||||
ans += [('Series', str(self.series) +
|
||||
' #%s' % self.format_series_index())]
|
||||
ans += [('Languages', ', '.join(self.languages))]
|
||||
if self.timestamp is not None:
|
||||
ans += [(_('Timestamp'), str(isoformat(self.timestamp, as_utc=False, sep=' ')))]
|
||||
ans += [('Timestamp', str(isoformat(self.timestamp, as_utc=False,
|
||||
sep=' ')))]
|
||||
if self.pubdate is not None:
|
||||
ans += [(_('Published'), str(isoformat(self.pubdate, as_utc=False, sep=' ')))]
|
||||
ans += [('Published', str(isoformat(self.pubdate, as_utc=False,
|
||||
sep=' ')))]
|
||||
if self.rights is not None:
|
||||
ans += [(_('Rights'), str(self.rights))]
|
||||
ans += [('Rights', str(self.rights))]
|
||||
for key in self.custom_field_keys():
|
||||
val = self.get(key, None)
|
||||
if val:
|
||||
|
||||
@@ -25,7 +25,7 @@ class SafeFormat(TemplateFormatter):
|
||||
if hasattr(self.book, orig_key):
|
||||
key = orig_key
|
||||
else:
|
||||
raise ValueError(_('Value: unknown field ') + orig_key)
|
||||
raise ValueError('Value: unknown field ' + orig_key)
|
||||
try:
|
||||
b = self.book.get_user_metadata(key, False)
|
||||
except:
|
||||
|
||||
@@ -110,7 +110,7 @@ def get_metadata(stream):
|
||||
root = _get_fbroot(get_fb2_data(stream)[0])
|
||||
ctx = Context(root)
|
||||
book_title = _parse_book_title(root, ctx)
|
||||
authors = _parse_authors(root, ctx) or [_('Unknown')]
|
||||
authors = _parse_authors(root, ctx) or ['Unknown']
|
||||
|
||||
# fallback for book_title
|
||||
if book_title:
|
||||
@@ -118,7 +118,7 @@ def get_metadata(stream):
|
||||
else:
|
||||
book_title = force_unicode(os.path.splitext(
|
||||
os.path.basename(getattr(stream, 'name',
|
||||
_('Unknown'))))[0])
|
||||
'Unknown')))[0])
|
||||
mi = MetaInformation(book_title, authors)
|
||||
|
||||
try:
|
||||
@@ -173,7 +173,7 @@ def _parse_authors(root, ctx):
|
||||
|
||||
# if no author so far
|
||||
if not authors:
|
||||
authors.append(_('Unknown'))
|
||||
authors.append('Unknown')
|
||||
|
||||
return authors
|
||||
|
||||
|
||||
@@ -151,10 +151,10 @@ def get_metadata_(src, encoding=None):
|
||||
return ans
|
||||
|
||||
# Title
|
||||
title = get('title') or title_tag.strip() or _('Unknown')
|
||||
title = get('title') or title_tag.strip() or 'Unknown'
|
||||
|
||||
# Author
|
||||
authors = authors_to_string(get_all('authors')) or _('Unknown')
|
||||
authors = authors_to_string(get_all('authors')) or 'Unknown'
|
||||
|
||||
# Create MetaInformation with Title and Author
|
||||
mi = Metadata(title, string_to_authors(authors))
|
||||
@@ -340,7 +340,7 @@ class MetadataHtmlTest(unittest.TestCase):
|
||||
|
||||
def test_input_title(self):
|
||||
stream_meta = get_metadata(self.get_stream('title'))
|
||||
canon_meta = Metadata('A Title Tag & Title Ⓒ', [_('Unknown')])
|
||||
canon_meta = Metadata('A Title Tag & Title Ⓒ', ['Unknown'])
|
||||
self.compare_metadata(stream_meta, canon_meta)
|
||||
|
||||
def test_input_meta_single(self):
|
||||
|
||||
@@ -33,7 +33,7 @@ def metadata_from_formats(formats, force_read_metadata=False, pattern=None):
|
||||
except:
|
||||
mi = metadata_from_filename(list(iter(formats))[0], pat=pattern)
|
||||
if not mi.authors:
|
||||
mi.authors = [_('Unknown')]
|
||||
mi.authors = ['Unknown']
|
||||
return mi
|
||||
|
||||
|
||||
@@ -61,9 +61,9 @@ def _metadata_from_formats(formats, force_read_metadata=False, pattern=None):
|
||||
return mi
|
||||
|
||||
if not mi.title:
|
||||
mi.title = _('Unknown')
|
||||
mi.title = 'Unknown'
|
||||
if not mi.authors:
|
||||
mi.authors = [_('Unknown')]
|
||||
mi.authors = ['Unknown']
|
||||
|
||||
return mi
|
||||
|
||||
@@ -106,9 +106,9 @@ def _get_metadata(stream, stream_type, use_libprs_metadata,
|
||||
base = metadata_from_filename(name, pat=pattern, fallback_pat=re.compile(
|
||||
r'^(?P<title>.+) - (?P<author>[^-]+)$'))
|
||||
if not base.authors:
|
||||
base.authors = [_('Unknown')]
|
||||
base.authors = ['Unknown']
|
||||
if not base.title:
|
||||
base.title = _('Unknown')
|
||||
base.title = 'Unknown'
|
||||
mi = MetaInformation(None, None)
|
||||
if force_read_metadata or prefs['read_file_metadata']:
|
||||
mi = get_file_type_metadata(stream, stream_type)
|
||||
|
||||
@@ -1360,7 +1360,7 @@ class OPFCreator(Metadata):
|
||||
if not isinstance(self.toc, TOC):
|
||||
self.toc = None
|
||||
if not self.authors:
|
||||
self.authors = [_('Unknown')]
|
||||
self.authors = ['Unknown']
|
||||
if self.guide is None:
|
||||
self.guide = Guide()
|
||||
if self.cover:
|
||||
@@ -1470,7 +1470,7 @@ class OPFCreator(Metadata):
|
||||
metadata = M.metadata()
|
||||
a = metadata.append
|
||||
role = {}
|
||||
a(DC_ELEM('title', self.title if self.title else _('Unknown'),
|
||||
a(DC_ELEM('title', self.title if self.title else 'Unknown',
|
||||
opf_attrs=role))
|
||||
for i, author in enumerate(self.authors):
|
||||
fa = {'role':'aut'}
|
||||
@@ -1679,7 +1679,7 @@ def metadata_to_opf(mi, as_string=True, default_lang=None):
|
||||
mi.cover = mi.cover.decode(filesystem_encoding)
|
||||
guide.text = '\n'+(' '*8)
|
||||
r = guide.makeelement(OPF('reference'),
|
||||
attrib={'type':'cover', 'title':_('Cover'), 'href':mi.cover})
|
||||
attrib={'type': 'cover', 'title': 'Cover', 'href': mi.cover})
|
||||
r.tail = '\n' +(' '*4)
|
||||
guide.append(r)
|
||||
if pretty_print_opf:
|
||||
|
||||
@@ -960,7 +960,7 @@ def set_last_modified_in_opf(root):
|
||||
|
||||
|
||||
def read_metadata(root, ver=None, return_extra_data=False):
|
||||
ans = Metadata(_('Unknown'), [_('Unknown')])
|
||||
ans = Metadata('Unknown', ['Unknown'])
|
||||
prefixes, refines = read_prefixes(root), read_refines(root)
|
||||
identifiers = read_identifiers(root, prefixes, refines)
|
||||
ids = {}
|
||||
|
||||
@@ -122,10 +122,10 @@ def get_metadata(stream, cover=True):
|
||||
with open(covpath, 'rb') as f:
|
||||
cdata = f.read()
|
||||
|
||||
title = info.get('Title', None) or _('Unknown')
|
||||
title = info.get('Title', None) or 'Unknown'
|
||||
au = info.get('Author', None)
|
||||
if au is None:
|
||||
au = [_('Unknown')]
|
||||
au = ['Unknown']
|
||||
else:
|
||||
au = string_to_authors(au)
|
||||
mi = MetaInformation(title, au)
|
||||
|
||||
@@ -110,10 +110,10 @@ def get_metadata(stream):
|
||||
"""
|
||||
stream.seek(0)
|
||||
if stream.read(5) != br'{\rtf':
|
||||
return MetaInformation(_('Unknown'))
|
||||
return MetaInformation('Unknown')
|
||||
block = get_document_info(stream)[0]
|
||||
if not block:
|
||||
return MetaInformation(_('Unknown'))
|
||||
return MetaInformation('Unknown')
|
||||
|
||||
stream.seek(0)
|
||||
cpg = detect_codepage(stream)
|
||||
@@ -123,7 +123,7 @@ def get_metadata(stream):
|
||||
if title_match is not None:
|
||||
title = decode(title_match.group(1).strip(), cpg)
|
||||
else:
|
||||
title = _('Unknown')
|
||||
title = 'Unknown'
|
||||
author_match = author_pat.search(block)
|
||||
if author_match is not None:
|
||||
author = decode(author_match.group(1).strip(), cpg)
|
||||
|
||||
@@ -17,7 +17,7 @@ def get_metadata(stream, extract_cover=True):
|
||||
name = getattr(stream, 'name', '').rpartition('.')[0]
|
||||
if name:
|
||||
name = os.path.basename(name)
|
||||
mi = MetaInformation(name or _('Unknown'), [_('Unknown')])
|
||||
mi = MetaInformation(name or 'Unknown', ['Unknown'])
|
||||
stream.seek(0)
|
||||
|
||||
mdata = ''
|
||||
|
||||
@@ -235,7 +235,7 @@ def more_recent(one, two):
|
||||
|
||||
def metadata_from_xmp_packet(raw_bytes):
|
||||
root = parse_xmp_packet(raw_bytes)
|
||||
mi = Metadata(_('Unknown'))
|
||||
mi = Metadata('Unknown')
|
||||
title = first_alt('//dc:title', root)
|
||||
if title:
|
||||
if title.startswith(r'\376\377'):
|
||||
@@ -346,7 +346,9 @@ def consolidate_metadata(info_mi, info):
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return info_mi
|
||||
info_title, info_authors, info_tags = info_mi.title or _('Unknown'), list(info_mi.authors or ()), list(info_mi.tags or ())
|
||||
info_title = info_mi.title or 'Unknown'
|
||||
info_authors = list(info_mi.authors or ())
|
||||
info_tags = list(info_mi.tags or ())
|
||||
info_mi.smart_update(xmp_mi, replace_metadata=True)
|
||||
prefer_info = False
|
||||
if 'ModDate' in info and hasattr(xmp_mi, 'metadata_date'):
|
||||
|
||||
Reference in New Issue
Block a user