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

View File

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

View File

@ -10,7 +10,7 @@ __docformat__ = 'restructuredtext en'
Crop a pdf file
'''
import os, sys, re
import sys, re
from optparse import OptionGroup, Option
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.')),
OptionRecommendation(name='bottom_left_x', recommended_value=DEFAULT_CROP,
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,
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,
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,
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,
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`')),
@ -72,7 +72,7 @@ def add_options(parser):
group = OptionGroup(parser, _('Crop Options:'), _('Options to control the transformation of pdf'))
parser.add_option_group(group)
add_option = group.add_option
for rec in OPTIONS:
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)
input_pdf = PdfFileReader(open(pdf_path, 'rb'))
bounding_lines = []
if opts.bounding != None:
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+)')
except:
raise Exception('Error reading %s' % opts.bounding)
lines = bounding.readlines()
for line in lines:
if line.startswith('%%BoundingBox:'):
bounding_lines.append(line)
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)
blines = iter(bounding_lines)
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.lowerLeft = (page.bleedBox.getLowerLeft_x() + opts.bottom_left_x, page.bleedBox.getLowerLeft_y() + opts.bottom_left_y)
output_pdf.addPage(page)
with open(opts.output, 'wb') as output_file:
output_pdf.write(output_file)
def main(args=sys.argv, name=''):
log = Log()
parser = option_parser(name)
add_options(parser)
opts, args = parser.parse_args(args)
args = args[1:]
if len(args) < 1:
print 'Error: A PDF file is required.\n'
print_help(parser, log)
return 1
if not is_valid_pdf(args[0]):
print 'Error: Could not read file `%s`.' % args[0]
return 1
if is_encrypted(args[0]):
print 'Error: file `%s` is encrypted.' % args[0]
return 1
mi = metadata_from_formats([args[0]])
crop_pdf(args[0], opts, mi)
return 0

View File

@ -32,12 +32,12 @@ class PDFOutput(OutputFormatPlugin):
level=OptionRecommendation.LOW, short_switch='u', choices=UNITS.keys(),
help=_('The unit of measure. Default is inch. Choices '
'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',
level=OptionRecommendation.LOW, choices=PAPER_SIZES.keys(),
help=_('The size of the paper. This size will be overridden when an '
'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,
help=_('Custom size of the document. Use the form widthxheight '
'EG. `123x321` to specify the width and height. '
@ -45,7 +45,7 @@ class PDFOutput(OutputFormatPlugin):
OptionRecommendation(name='orientation', recommended_value='portrait',
level=OptionRecommendation.LOW, choices=ORIENTATIONS.keys(),
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):

View File

@ -23,7 +23,7 @@ class TXTOutput(OutputFormatPlugin):
help=_('Type of newline to use. Options are %s. Default is \'system\'. '
'Use \'old_mac\' for compatibility with Mac OS 9 and earlier. '
'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):
@ -38,11 +38,11 @@ class TXTOutput(OutputFormatPlugin):
out_stream = open(output_path, 'wb')
else:
out_stream = output_path
out_stream.seek(0)
out_stream.truncate()
out_stream.write(txt.encode('utf-8'))
if 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)
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_()
return jobs, changed, bad
@ -122,7 +123,8 @@ def convert_bulk_ebook(parent, db, book_ids, out_format=None):
msg = '%s' % '\n'.join(res)
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_()
return jobs, changed, bad

File diff suppressed because it is too large Load Diff