Fix #756736 (Tweaks not translated)

This commit is contained in:
Kovid Goyal 2011-04-10 15:43:48 -06:00
parent e35860a2b2
commit 0e8f01a545
5 changed files with 751 additions and 346 deletions

View File

@ -170,8 +170,8 @@ from setup import __appname__, __version__ as version
# there.
pot_header = '''\
# Translation template file..
# Copyright (C) 2007 Kovid Goyal
# Kovid Goyal <kovid@kovidgoyal.net>, 2007.
# Copyright (C) %(year)s Kovid Goyal
# Kovid Goyal <kovid@kovidgoyal.net>, %(year)s.
#
msgid ""
msgstr ""
@ -185,7 +185,7 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\\n"
"Generated-By: pygettext.py %%(version)s\\n"
'''%dict(appname=__appname__, version=version)
'''%dict(appname=__appname__, version=version, year=time.strftime('%Y'))
def usage(code, msg=''):

View File

@ -26,6 +26,38 @@ class POT(Command):
ans.append(os.path.abspath(os.path.join(root, name)))
return ans
def get_tweaks_docs(self):
path = self.a(self.j(self.SRC, '..', 'resources', 'default_tweaks.py'))
with open(path, 'rb') as f:
raw = f.read().decode('utf-8')
msgs = []
lines = list(raw.splitlines())
for i, line in enumerate(lines):
if line.startswith('#:'):
msgs.append((i, line[2:].strip()))
j = i
block = []
while True:
j += 1
line = lines[j]
if not line.startswith('#'):
break
block.append(line[1:].strip())
if block:
msgs.append((i+1, '\n'.join(block)))
ans = []
for lineno, msg in msgs:
ans.append('#: %s:%d'%(path, lineno))
slash = unichr(92)
msg = msg.replace(slash, slash*2).replace('"', r'\"').replace('\n',
r'\n').replace('\r', r'\r').replace('\t', r'\t')
ans.append('msgid "%s"'%msg)
ans.append('msgstr ""')
ans.append('')
return '\n'.join(ans)
def run(self, opts):
files = self.source_files()
@ -35,10 +67,10 @@ class POT(Command):
atexit.register(shutil.rmtree, tempdir)
pygettext(buf, ['-k', '__', '-p', tempdir]+files)
src = buf.getvalue()
src += '\n\n' + self.get_tweaks_docs()
pot = os.path.join(self.PATH, __appname__+'.pot')
f = open(pot, 'wb')
with open(pot, 'wb') as f:
f.write(src)
f.close()
self.info('Translations template:', os.path.abspath(pot))
return pot

View File

@ -155,7 +155,7 @@ class FB2Output(OutputFormatPlugin):
OptionRecommendation(name='fb2_genre',
recommended_value='antique', level=OptionRecommendation.LOW,
choices=FB2_GENRES,
help=_('Genre for the book. Choices: %s\n\n See: ' % FB2_GENRES) + 'http://www.fictionbook.org/index.php/Eng:FictionBook_2.1_genres ' \
help=(_('Genre for the book. Choices: %s\n\n See: ') % FB2_GENRES) + 'http://www.fictionbook.org/index.php/Eng:FictionBook_2.1_genres ' \
+ _('for a complete list with descriptions.')),
])

View File

@ -14,9 +14,9 @@ from calibre.utils.config import read_raw_tweaks, write_tweaks
from calibre.gui2.widgets import PythonHighlighter
from calibre import isbytestring
from PyQt4.Qt import QAbstractListModel, Qt, QStyledItemDelegate, QStyle, \
QStyleOptionViewItem, QFont, QDialogButtonBox, QDialog, \
QVBoxLayout, QPlainTextEdit, QLabel
from PyQt4.Qt import (QAbstractListModel, Qt, QStyledItemDelegate, QStyle,
QStyleOptionViewItem, QFont, QDialogButtonBox, QDialog,
QVBoxLayout, QPlainTextEdit, QLabel)
class Delegate(QStyledItemDelegate): # {{{
def __init__(self, view):
@ -35,8 +35,9 @@ class Delegate(QStyledItemDelegate): # {{{
class Tweak(object): # {{{
def __init__(self, name, doc, var_names, defaults, custom):
self.name = name
self.doc = doc.strip()
translate = __builtins__['_']
self.name = translate(name)
self.doc = translate(doc.strip())
self.var_names = var_names
self.default_values = {}
for x in var_names:

File diff suppressed because it is too large Load Diff