IGN:More translatable phrases in Mobipocket output

This commit is contained in:
Kovid Goyal 2009-01-20 17:58:34 -08:00
commit 5da7a6af7e
4 changed files with 40 additions and 15 deletions

View File

@ -121,7 +121,7 @@ if __name__ == '__main__':
buf = cStringIO.StringIO() buf = cStringIO.StringIO()
print 'Creating translations template' print 'Creating translations template'
tempdir = tempfile.mkdtemp() tempdir = tempfile.mkdtemp()
pygettext(buf, ['-p', tempdir]+files) pygettext(buf, ['-k', '__', '-p', tempdir]+files)
src = buf.getvalue() src = buf.getvalue()
pot = os.path.join(tempdir, 'calibre.pot') pot = os.path.join(tempdir, 'calibre.pot')
f = open(pot, 'wb') f = open(pot, 'wb')

View File

@ -535,27 +535,36 @@ class Spine(object):
class Guide(object): class Guide(object):
class Reference(object): class Reference(object):
_TYPES_TITLES = [('cover', 'Cover'), ('title-page', 'Title Page'), _TYPES_TITLES = [('cover', __('Cover')),
('toc', 'Table of Contents'), ('index', 'Index'), ('title-page', __('Title Page')),
('glossary', 'Glossary'), ('acknowledgements', 'Acknowledgements'), ('toc', __('Table of Contents')),
('bibliography', 'Bibliography'), ('colophon', 'Colophon'), ('index', __('Index')),
('copyright-page', 'Copyright'), ('dedication', 'Dedication'), ('glossary', __('Glossary')),
('epigraph', 'Epigraph'), ('foreword', 'Foreword'), ('acknowledgements', __('Acknowledgements')),
('loi', 'List of Illustrations'), ('lot', 'List of Tables'), ('bibliography', __('Bibliography')),
('notes', 'Notes'), ('preface', 'Preface'), ('colophon', __('Colophon')),
('text', 'Main Text')] ('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) TYPES = set(t for t, _ in _TYPES_TITLES)
TITLES = dict(_TYPES_TITLES) TITLES = dict(_TYPES_TITLES)
ORDER = dict((t, i) for (t, _), i in izip(_TYPES_TITLES, count(0))) 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: if type.lower() in self.TYPES:
type = type.lower() type = type.lower()
elif type not in self.TYPES and \ elif type not in self.TYPES and \
not type.startswith('other.'): not type.startswith('other.'):
type = 'other.' + type type = 'other.' + type
if not title: if not title and type in self.TITLES:
title = self.TITLES.get(type, None) title = oeb.translate(self.TITLES[type])
self.type = type self.type = type
self.title = title self.title = title
self.href = urlnormalize(href) self.href = urlnormalize(href)
@ -574,13 +583,21 @@ class Guide(object):
if not isinstance(other, Guide.Reference): if not isinstance(other, Guide.Reference):
return NotImplemented return NotImplemented
return cmp(self._order, other._order) 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): def __init__(self, oeb):
self.oeb = oeb self.oeb = oeb
self.refs = {} self.refs = {}
def add(self, type, title, href): def add(self, type, title, href):
ref = self.Reference(type, title, href) ref = self.Reference(self.oeb, type, title, href)
self.refs[type] = ref self.refs[type] = ref
return ref return ref

View File

@ -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 XHTML_MIME, CSS_MIME
from calibre.ebooks.oeb.base import element from calibre.ebooks.oeb.base import element
__all__ = ['HTMLTOCAdder']
DEFAULT_TITLE = __('Table of Contents')
STYLE_CSS = { STYLE_CSS = {
'nested': """ 'nested': """
.calibre_toc_header { .calibre_toc_header {
@ -52,7 +56,7 @@ class HTMLTOCAdder(object):
if 'toc' in oeb.guide: if 'toc' in oeb.guide:
return return
oeb.logger.info('Generating in-line TOC...') 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 style = self.style
if style not in STYLE_CSS: if style not in STYLE_CSS:
oeb.logger.error('Unknown TOC style %r' % style) oeb.logger.error('Unknown TOC style %r' % style)

View File

@ -13,6 +13,10 @@ from gettext import GNUTranslations
import __builtin__ import __builtin__
__builtin__.__dict__['_'] = lambda s: s __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.constants import iswindows, preferred_encoding, plugins
from calibre.utils.config import prefs from calibre.utils.config import prefs
from calibre.translations.msgfmt import make from calibre.translations.msgfmt import make