diff --git a/setup.py b/setup.py index 2f0c5aad26..6bc4109277 100644 --- a/setup.py +++ b/setup.py @@ -121,7 +121,7 @@ if __name__ == '__main__': buf = cStringIO.StringIO() print 'Creating translations template' tempdir = tempfile.mkdtemp() - pygettext(buf, ['-p', tempdir]+files) + pygettext(buf, ['-k', '__', '-p', tempdir]+files) src = buf.getvalue() pot = os.path.join(tempdir, 'calibre.pot') f = open(pot, 'wb') diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index c167151a5f..c44ffcd8d9 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -535,27 +535,36 @@ class Spine(object): class Guide(object): class Reference(object): - _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'))] TYPES = set(t for t, _ in _TYPES_TITLES) TITLES = dict(_TYPES_TITLES) ORDER = dict((t, i) for (t, _), i in izip(_TYPES_TITLES, count(0))) - def __init__(self, type, title, href): + def __init__(self, oeb, type, title, href): + self.oeb = oeb if type.lower() in self.TYPES: type = type.lower() elif type not in self.TYPES and \ not type.startswith('other.'): type = 'other.' + type - if not title: - title = self.TITLES.get(type, None) + if not title and type in self.TITLES: + title = oeb.translate(self.TITLES[type]) self.type = type self.title = title self.href = urlnormalize(href) @@ -574,13 +583,21 @@ class Guide(object): if not isinstance(other, Guide.Reference): return NotImplemented return cmp(self._order, other._order) + + def item(): + def fget(self): + path, frag = urldefrag(self.href) + hrefs = self.oeb.manifest.hrefs + return hrefs.get(path, None) + return property(fget=fget) + item = item() def __init__(self, oeb): self.oeb = oeb self.refs = {} def add(self, type, title, href): - ref = self.Reference(type, title, href) + ref = self.Reference(self.oeb, type, title, href) self.refs[type] = ref return ref diff --git a/src/calibre/ebooks/oeb/transforms/htmltoc.py b/src/calibre/ebooks/oeb/transforms/htmltoc.py index 7da7df17e9..5508b58ec3 100644 --- a/src/calibre/ebooks/oeb/transforms/htmltoc.py +++ b/src/calibre/ebooks/oeb/transforms/htmltoc.py @@ -13,6 +13,10 @@ from calibre.ebooks.oeb.base import XML, XHTML, XHTML_NS from calibre.ebooks.oeb.base import XHTML_MIME, CSS_MIME from calibre.ebooks.oeb.base import element +__all__ = ['HTMLTOCAdder'] + +DEFAULT_TITLE = __('Table of Contents') + STYLE_CSS = { 'nested': """ .calibre_toc_header { @@ -52,7 +56,7 @@ class HTMLTOCAdder(object): if 'toc' in oeb.guide: return oeb.logger.info('Generating in-line TOC...') - title = self.title or oeb.translate('Table of Contents') + title = self.title or oeb.translate(DEFAULT_TITLE) style = self.style if style not in STYLE_CSS: oeb.logger.error('Unknown TOC style %r' % style) diff --git a/src/calibre/startup.py b/src/calibre/startup.py index eebec7d784..6cf155792e 100644 --- a/src/calibre/startup.py +++ b/src/calibre/startup.py @@ -13,6 +13,10 @@ from gettext import GNUTranslations import __builtin__ __builtin__.__dict__['_'] = lambda s: s +# For strings which belong in the translation tables, but which shouldn't be +# immediately translated to the environment language +__builtin__.__dict__['__'] = lambda s: s + from calibre.constants import iswindows, preferred_encoding, plugins from calibre.utils.config import prefs from calibre.translations.msgfmt import make