Updated translatable strings

This commit is contained in:
Kovid Goyal 2009-05-31 09:37:12 -07:00
parent a52242cecb
commit c3e5c50f98
7 changed files with 2956 additions and 2439 deletions

View File

@ -15,13 +15,13 @@ class PDBOutput(OutputFormatPlugin):
name = 'PDB Output' name = 'PDB Output'
author = 'John Schember' author = 'John Schember'
file_type = 'pdb' file_type = 'pdb'
options = set([ options = set([
OptionRecommendation(name='format', recommended_value='doc', OptionRecommendation(name='format', recommended_value='doc',
level=OptionRecommendation.LOW, level=OptionRecommendation.LOW,
short_switch='f', choices=FORMAT_WRITERS.keys(), short_switch='f', choices=FORMAT_WRITERS.keys(),
help=_('Format to use inside the pdb container. Choices are: ' help=(_('Format to use inside the pdb container. Choices are:')+\
'%s' % FORMAT_WRITERS.keys())), ' %s' % FORMAT_WRITERS.keys())),
]) ])
def convert(self, oeb_book, output_path, input_plugin, opts, log): def convert(self, oeb_book, output_path, input_plugin, opts, log):
@ -33,19 +33,19 @@ class PDBOutput(OutputFormatPlugin):
out_stream = open(output_path, 'wb') out_stream = open(output_path, 'wb')
else: else:
out_stream = output_path out_stream = output_path
Writer = get_writer(opts.format) Writer = get_writer(opts.format)
if Writer is None: if Writer is None:
raise PDBError('No writer avaliable for format %s.' % format) raise PDBError('No writer avaliable for format %s.' % format)
writer = Writer(opts, log) writer = Writer(opts, log)
out_stream.seek(0) out_stream.seek(0)
out_stream.truncate() out_stream.truncate()
writer.write_content(oeb_book, out_stream, oeb_book.metadata) writer.write_content(oeb_book, out_stream, oeb_book.metadata)
if close: if close:
out_stream.close() out_stream.close()

View File

@ -14,7 +14,6 @@ import string, sys
from calibre.utils.config import OptionParser from calibre.utils.config import OptionParser
from calibre.utils.logging import Log from calibre.utils.logging import Log
from calibre.constants import preferred_encoding from calibre.constants import preferred_encoding
from calibre.customize.conversion import OptionRecommendation
from calibre.ebooks.pdf.manipulate import crop, decrypt, encrypt, \ from calibre.ebooks.pdf.manipulate import crop, decrypt, encrypt, \
info, merge, reverse, rotate, split info, merge, reverse, rotate, split
@ -30,14 +29,14 @@ COMMANDS = {
} }
USAGE = '%prog ' + _('''command ... USAGE = '%prog ' + _('''command ...
command can be one of the following: command can be one of the following:
[%%commands] [%%commands]
Use %prog command --help to get more information about a specific command Use %prog command --help to get more information about a specific command
Manipulate a PDF. Manipulate a PDF.
'''.replace('%%commands', string.join(sorted(COMMANDS.keys()), ', '))) ''').replace('%%commands', string.join(sorted(COMMANDS.keys()), ', '))
def print_help(parser, log): def print_help(parser, log):
help = parser.format_help().encode(preferred_encoding, 'replace') help = parser.format_help().encode(preferred_encoding, 'replace')
@ -54,9 +53,9 @@ def main(args=sys.argv):
print 'Error: No command sepecified.\n' print 'Error: No command sepecified.\n'
print_help(parser, log) print_help(parser, log)
return 1 return 1
command = args[1].lower().strip() command = args[1].lower().strip()
if command in COMMANDS.keys(): if command in COMMANDS.keys():
del args[1] del args[1]
return COMMANDS[command].main(args, command) return COMMANDS[command].main(args, command)
@ -65,7 +64,7 @@ def main(args=sys.argv):
print 'Unknown command %s.\n' % command print 'Unknown command %s.\n' % command
print_help(parser, log) print_help(parser, log)
return 1 return 1
# We should never get here. # We should never get here.
return 0 return 0

View File

@ -10,7 +10,7 @@ __docformat__ = 'restructuredtext en'
Crop a pdf file Crop a pdf file
''' '''
import os, sys, re import sys, re
from optparse import OptionGroup, Option from optparse import OptionGroup, Option
from calibre.ebooks.metadata.meta import metadata_from_formats from calibre.ebooks.metadata.meta import metadata_from_formats
@ -37,16 +37,16 @@ OPTIONS = set([
help=_('Path to output file. By default a file is created in the current directory.')), help=_('Path to output file. By default a file is created in the current directory.')),
OptionRecommendation(name='bottom_left_x', recommended_value=DEFAULT_CROP, OptionRecommendation(name='bottom_left_x', recommended_value=DEFAULT_CROP,
level=OptionRecommendation.LOW, long_switch='leftx', short_switch='x', level=OptionRecommendation.LOW, long_switch='leftx', short_switch='x',
help=_('Number of pixels to crop from the left most x (default is %s) ' % DEFAULT_CROP)), help=_('Number of pixels to crop from the left most x (default is %s)') % DEFAULT_CROP),
OptionRecommendation(name='bottom_left_y', recommended_value=DEFAULT_CROP, OptionRecommendation(name='bottom_left_y', recommended_value=DEFAULT_CROP,
level=OptionRecommendation.LOW, long_switch='lefty', short_switch='y', level=OptionRecommendation.LOW, long_switch='lefty', short_switch='y',
help=_('Number of pixels to crop from the left most y (default is %s) ' % DEFAULT_CROP)), help=_('Number of pixels to crop from the left most y (default is %s)') % DEFAULT_CROP),
OptionRecommendation(name='top_right_x', recommended_value=DEFAULT_CROP, OptionRecommendation(name='top_right_x', recommended_value=DEFAULT_CROP,
level=OptionRecommendation.LOW, long_switch='rightx', short_switch='v', level=OptionRecommendation.LOW, long_switch='rightx', short_switch='v',
help=_('Number of pixels to crop from the right most x (default is %s) ' % DEFAULT_CROP)), help=_('Number of pixels to crop from the right most x (default is %s)') % DEFAULT_CROP),
OptionRecommendation(name='top_right_y', recommended_value=DEFAULT_CROP, OptionRecommendation(name='top_right_y', recommended_value=DEFAULT_CROP,
level=OptionRecommendation.LOW, long_switch='right y', short_switch='w', level=OptionRecommendation.LOW, long_switch='right y', short_switch='w',
help=_('Number of pixels to crop from the right most y (default is %s)' % DEFAULT_CROP)), help=_('Number of pixels to crop from the right most y (default is %s)') % DEFAULT_CROP),
OptionRecommendation(name='bounding', recommended_value=None, OptionRecommendation(name='bounding', recommended_value=None,
level=OptionRecommendation.LOW, long_switch='bounding', short_switch='b', level=OptionRecommendation.LOW, long_switch='bounding', short_switch='b',
help=_('A file generated by ghostscript which allows each page to be individually cropped `gs -dSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox file.pdf 2> bounding`')), help=_('A file generated by ghostscript which allows each page to be individually cropped `gs -dSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox file.pdf 2> bounding`')),
@ -72,7 +72,7 @@ def add_options(parser):
group = OptionGroup(parser, _('Crop Options:'), _('Options to control the transformation of pdf')) group = OptionGroup(parser, _('Crop Options:'), _('Options to control the transformation of pdf'))
parser.add_option_group(group) parser.add_option_group(group)
add_option = group.add_option add_option = group.add_option
for rec in OPTIONS: for rec in OPTIONS:
option_recommendation_to_cli_option(add_option, rec) option_recommendation_to_cli_option(add_option, rec)
@ -85,7 +85,7 @@ def crop_pdf(pdf_path, opts, metadata=None):
author = authors_to_string(metadata.authors) author = authors_to_string(metadata.authors)
input_pdf = PdfFileReader(open(pdf_path, 'rb')) input_pdf = PdfFileReader(open(pdf_path, 'rb'))
bounding_lines = [] bounding_lines = []
if opts.bounding != None: if opts.bounding != None:
try: try:
@ -93,14 +93,14 @@ def crop_pdf(pdf_path, opts, metadata=None):
bounding_regex = re.compile('%%BoundingBox: (?P<bottom_x>\d+) (?P<bottom_y>\d+) (?P<top_x>\d+) (?P<top_y>\d+)') bounding_regex = re.compile('%%BoundingBox: (?P<bottom_x>\d+) (?P<bottom_y>\d+) (?P<top_x>\d+) (?P<top_y>\d+)')
except: except:
raise Exception('Error reading %s' % opts.bounding) raise Exception('Error reading %s' % opts.bounding)
lines = bounding.readlines() lines = bounding.readlines()
for line in lines: for line in lines:
if line.startswith('%%BoundingBox:'): if line.startswith('%%BoundingBox:'):
bounding_lines.append(line) bounding_lines.append(line)
if len(bounding_lines) != input_pdf.numPages: if len(bounding_lines) != input_pdf.numPages:
raise Exception('Error bounding file %s page count does not correspond to specified pdf' % opts.bounding) raise Exception('Error bounding file %s page count does not correspond to specified pdf' % opts.bounding)
output_pdf = PdfFileWriter(title=title,author=author) output_pdf = PdfFileWriter(title=title,author=author)
blines = iter(bounding_lines) blines = iter(bounding_lines)
for page in input_pdf.pages: for page in input_pdf.pages:
@ -114,33 +114,33 @@ def crop_pdf(pdf_path, opts, metadata=None):
page.mediaBox.upperRight = (page.bleedBox.getUpperRight_x() - opts.top_right_x, page.bleedBox.getUpperRight_y() - opts.top_right_y) page.mediaBox.upperRight = (page.bleedBox.getUpperRight_x() - opts.top_right_x, page.bleedBox.getUpperRight_y() - opts.top_right_y)
page.mediaBox.lowerLeft = (page.bleedBox.getLowerLeft_x() + opts.bottom_left_x, page.bleedBox.getLowerLeft_y() + opts.bottom_left_y) page.mediaBox.lowerLeft = (page.bleedBox.getLowerLeft_x() + opts.bottom_left_x, page.bleedBox.getLowerLeft_y() + opts.bottom_left_y)
output_pdf.addPage(page) output_pdf.addPage(page)
with open(opts.output, 'wb') as output_file: with open(opts.output, 'wb') as output_file:
output_pdf.write(output_file) output_pdf.write(output_file)
def main(args=sys.argv, name=''): def main(args=sys.argv, name=''):
log = Log() log = Log()
parser = option_parser(name) parser = option_parser(name)
add_options(parser) add_options(parser)
opts, args = parser.parse_args(args) opts, args = parser.parse_args(args)
args = args[1:] args = args[1:]
if len(args) < 1: if len(args) < 1:
print 'Error: A PDF file is required.\n' print 'Error: A PDF file is required.\n'
print_help(parser, log) print_help(parser, log)
return 1 return 1
if not is_valid_pdf(args[0]): if not is_valid_pdf(args[0]):
print 'Error: Could not read file `%s`.' % args[0] print 'Error: Could not read file `%s`.' % args[0]
return 1 return 1
if is_encrypted(args[0]): if is_encrypted(args[0]):
print 'Error: file `%s` is encrypted.' % args[0] print 'Error: file `%s` is encrypted.' % args[0]
return 1 return 1
mi = metadata_from_formats([args[0]]) mi = metadata_from_formats([args[0]])
crop_pdf(args[0], opts, mi) crop_pdf(args[0], opts, mi)
return 0 return 0

View File

@ -32,12 +32,12 @@ class PDFOutput(OutputFormatPlugin):
level=OptionRecommendation.LOW, short_switch='u', choices=UNITS.keys(), level=OptionRecommendation.LOW, short_switch='u', choices=UNITS.keys(),
help=_('The unit of measure. Default is inch. Choices ' help=_('The unit of measure. Default is inch. Choices '
'are %s ' 'are %s '
'Note: This does not override the unit for margins!' % UNITS.keys())), 'Note: This does not override the unit for margins!') % UNITS.keys()),
OptionRecommendation(name='paper_size', recommended_value='letter', OptionRecommendation(name='paper_size', recommended_value='letter',
level=OptionRecommendation.LOW, choices=PAPER_SIZES.keys(), level=OptionRecommendation.LOW, choices=PAPER_SIZES.keys(),
help=_('The size of the paper. This size will be overridden when an ' help=_('The size of the paper. This size will be overridden when an '
'output profile is used. Default is letter. Choices ' 'output profile is used. Default is letter. Choices '
'are %s' % PAPER_SIZES.keys())), 'are %s') % PAPER_SIZES.keys()),
OptionRecommendation(name='custom_size', recommended_value=None, OptionRecommendation(name='custom_size', recommended_value=None,
help=_('Custom size of the document. Use the form widthxheight ' help=_('Custom size of the document. Use the form widthxheight '
'EG. `123x321` to specify the width and height. ' 'EG. `123x321` to specify the width and height. '
@ -45,7 +45,7 @@ class PDFOutput(OutputFormatPlugin):
OptionRecommendation(name='orientation', recommended_value='portrait', OptionRecommendation(name='orientation', recommended_value='portrait',
level=OptionRecommendation.LOW, choices=ORIENTATIONS.keys(), level=OptionRecommendation.LOW, choices=ORIENTATIONS.keys(),
help=_('The orientation of the page. Default is portrait. Choices ' help=_('The orientation of the page. Default is portrait. Choices '
'are %s' % ORIENTATIONS.keys())), 'are %s') % ORIENTATIONS.keys()),
]) ])
def convert(self, oeb_book, output_path, input_plugin, opts, log): def convert(self, oeb_book, output_path, input_plugin, opts, log):

View File

@ -23,7 +23,7 @@ class TXTOutput(OutputFormatPlugin):
help=_('Type of newline to use. Options are %s. Default is \'system\'. ' help=_('Type of newline to use. Options are %s. Default is \'system\'. '
'Use \'old_mac\' for compatibility with Mac OS 9 and earlier. ' 'Use \'old_mac\' for compatibility with Mac OS 9 and earlier. '
'For Mac OS X use \'unix\'. \'system\' will default to the newline ' 'For Mac OS X use \'unix\'. \'system\' will default to the newline '
'type used by this OS.' % sorted(TxtNewlines.NEWLINE_TYPES.keys()))), 'type used by this OS.') % sorted(TxtNewlines.NEWLINE_TYPES.keys())),
]) ])
def convert(self, oeb_book, output_path, input_plugin, opts, log): def convert(self, oeb_book, output_path, input_plugin, opts, log):
@ -38,11 +38,11 @@ class TXTOutput(OutputFormatPlugin):
out_stream = open(output_path, 'wb') out_stream = open(output_path, 'wb')
else: else:
out_stream = output_path out_stream = output_path
out_stream.seek(0) out_stream.seek(0)
out_stream.truncate() out_stream.truncate()
out_stream.write(txt.encode('utf-8')) out_stream.write(txt.encode('utf-8'))
if close: if close:
out_stream.close() out_stream.close()

View File

@ -68,7 +68,8 @@ def convert_single_ebook(parent, db, book_ids, auto_conversion=False, out_format
msg = '%s' % '\n'.join(res) msg = '%s' % '\n'.join(res)
warning_dialog(parent, _('Could not convert some books'), warning_dialog(parent, _('Could not convert some books'),
_('Could not convert %d of %d books, because no suitable source format was found.' % (len(res), total)), _('Could not convert %d of %d books, because no suitable source'
' format was found.') % (len(res), total),
msg).exec_() msg).exec_()
return jobs, changed, bad return jobs, changed, bad
@ -122,7 +123,8 @@ def convert_bulk_ebook(parent, db, book_ids, out_format=None):
msg = '%s' % '\n'.join(res) msg = '%s' % '\n'.join(res)
warning_dialog(parent, _('Could not convert some books'), warning_dialog(parent, _('Could not convert some books'),
_('Could not convert %d of %d books, because no suitable source format was found.' % (len(res), total)), _('Could not convert %d of %d books, because no suitable '
'source format was found.') % (len(res), total),
msg).exec_() msg).exec_()
return jobs, changed, bad return jobs, changed, bad

File diff suppressed because it is too large Load Diff