diff --git a/Makefile b/Makefile index 62207b85a7..6210b41c95 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,11 @@ -all : gui2 +all : gui2 translations clean : - ${MAKE} -C src/libprs500/gui2 clean + cd src/libprs500/gui2 && python make.py clean gui2 : - ${MAKE} -C src/libprs500/gui2 + cd src/libprs500/gui2 && python make.py + +translations : + cd src/libprs500 && python translations/__init__.py + diff --git a/src/libprs500/__init__.py b/src/libprs500/__init__.py index 199915ac27..7726b83c1e 100644 --- a/src/libprs500/__init__.py +++ b/src/libprs500/__init__.py @@ -18,11 +18,17 @@ __docformat__ = "epytext" __author__ = "Kovid Goyal " __appname__ = 'libprs500' -import sys, os, logging, mechanize +import sys, os, logging, mechanize, locale, cStringIO +from gettext import GNUTranslations + iswindows = 'win32' in sys.platform.lower() isosx = 'darwin' in sys.platform.lower() islinux = not(iswindows or isosx) +# Default translation is NOOP +import __builtin__ +__builtin__.__dict__['_'] = lambda s: s + class CommandLineError(Exception): pass @@ -62,12 +68,12 @@ def extract(path, dir): ext = os.path.splitext(path)[1][1:].lower() extractor = None if ext == 'zip': - from libprs500.libunzip import extract - extractor = extract + from libprs500.libunzip import extract as zipextract + extractor = zipextract elif ext == 'rar': - from libprs500.libunrar import extract # In case the dll is not found - extractor = extract - if not extractor: + from libprs500.libunrar import extract as rarextract + extractor = rarextract + if extractor is None: raise Exception('Unknown archive type') extractor(path, dir) @@ -78,4 +84,16 @@ def browser(): opener.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; i686 Linux; en_US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4')] return opener +def set_translator(): + # To test different translations invoke as + # LC_ALL=de_DE.utf8 program + from libprs500.translations.data import translations + lang = locale.getdefaultlocale()[0] + if lang: + lang = lang[:2] + if translations.has_key(lang): + buf = cStringIO.StringIO(translations[lang]) + t = GNUTranslations(buf) + t.install(unicode=True) + \ No newline at end of file diff --git a/src/libprs500/ebooks/lrf/__init__.py b/src/libprs500/ebooks/lrf/__init__.py index 28d41d76e9..7823e2a1e7 100644 --- a/src/libprs500/ebooks/lrf/__init__.py +++ b/src/libprs500/ebooks/lrf/__init__.py @@ -87,90 +87,91 @@ def font_family(option, opt_str, value, parser): def option_parser(usage): parser = OptionParser(usage=usage, version=__appname__+' '+__version__, - epilog='Created by '+__author__) + epilog=_('Created by ')+__author__) metadata = parser.add_option_group('METADATA OPTIONS') metadata.add_option("-t", "--title", action="store", type="string", default=None,\ - dest="title", help="Set the title. Default: filename.") + dest="title", help=_("Set the title. Default: filename.")) metadata.add_option("-a", "--author", action="store", type="string", \ - dest="author", help="Set the author(s). Multiple authors should be set as a comma separated list. Default: %default", default='Unknown') + dest="author", help=_("Set the author(s). Multiple authors should be set as a comma separated list. Default: %default"), + default=_('Unknown')) metadata.add_option("--comment", action="store", type="string", \ - dest="freetext", help="Set the comment.", default=' ') + dest="freetext", help=_("Set the comment."), default=' ') metadata.add_option("--category", action="store", type="string", \ - dest="category", help="Set the category", default=' ') + dest="category", help=_("Set the category"), default=' ') metadata.add_option('--title-sort', action='store', default='', dest='title_sort', - help='Sort key for the title') + help=_('Sort key for the title')) metadata.add_option('--author-sort', action='store', default='', dest='author_sort', - help='Sort key for the author') + help=_('Sort key for the author')) metadata.add_option('--publisher', action='store', default='Unknown', dest='publisher', - help='Publisher') + help=_('Publisher')) metadata.add_option('--cover', action='store', dest='cover', default=None, \ - help='Path to file containing image to be used as cover') + help=_('Path to file containing image to be used as cover')) metadata.add_option('--use-metadata-cover', action='store_true', default=False, - help='If there is a cover graphic detected in the source file, use that instead of the specified cover.') + help=_('If there is a cover graphic detected in the source file, use that instead of the specified cover.')) parser.add_option('-o', '--output', action='store', default=None, \ - help='Output file name. Default is derived from input filename') + help=_('Output file name. Default is derived from input filename')) parser.add_option('--ignore-tables', action='store_true', default=False, dest='ignore_tables', - help='Render HTML tables as blocks of text instead of actual tables. This is neccessary if the HTML contains very large or complex tables.') + help=_('Render HTML tables as blocks of text instead of actual tables. This is neccessary if the HTML contains very large or complex tables.')) laf = parser.add_option_group('LOOK AND FEEL') laf.add_option('--font-delta', action='store', type='float', default=0., \ - help="""Increase the font size by 2 * FONT_DELTA pts and """ + help=_("""Increase the font size by 2 * FONT_DELTA pts and """ '''the line spacing by FONT_DELTA pts. FONT_DELTA can be a fraction.''' - """If FONT_DELTA is negative, the font size is decreased.""", + """If FONT_DELTA is negative, the font size is decreased."""), dest='font_delta') laf.add_option('--enable-autorotation', action='store_true', default=False, - help='Enable autorotation of images that are wider than the screen width.', + help=_('Enable autorotation of images that are wider than the screen width.'), dest='autorotation') laf.add_option('--wordspace', dest='wordspace', default=2.5, type='float', - help='Set the space between words in pts. Default is %default') + help=_('Set the space between words in pts. Default is %default')) laf.add_option('--blank-after-para', action='store_true', default=False, - dest='blank_after_para', help='Separate paragraphs by blank lines.') + dest='blank_after_para', help=_('Separate paragraphs by blank lines.')) laf.add_option('--header', action='store_true', default=False, dest='header', - help='Add a header to all the pages with title and author.') + help=_('Add a header to all the pages with title and author.')) laf.add_option('--headerformat', default="%t by %a", dest='headerformat', type='string', - help='Set the format of the header. %a is replaced by the author and %t by the title. Default is %default') + help=_('Set the format of the header. %a is replaced by the author and %t by the title. Default is %default')) laf.add_option('--override-css', default=None, dest='_override_css', type='string', - help='Override the CSS. Can be either a path to a CSS stylesheet or a string. If it is a string it is interpreted as CSS.') + help=_('Override the CSS. Can be either a path to a CSS stylesheet or a string. If it is a string it is interpreted as CSS.')) laf.add_option('--use-spine', default=False, dest='use_spine', action='store_true', - help='Use the element from the OPF file to determine the order in which the HTML files are appended to the LRF. The .opf file must be in the same directory as the base HTML file.') + help=_('Use the element from the OPF file to determine the order in which the HTML files are appended to the LRF. The .opf file must be in the same directory as the base HTML file.')) page = parser.add_option_group('PAGE OPTIONS') profiles = profile_map.keys() page.add_option('-p', '--profile', default=PRS500_PROFILE, dest='profile', type='choice', choices=profiles, action='callback', callback=profile_from_string, - help='''Profile of the target device for which this LRF is ''' + help=_('''Profile of the target device for which this LRF is ''' '''being generated. The profile determines things like the ''' '''resolution and screen size of the target device. ''' - '''Default: %s Supported profiles: '''%(PRS500_PROFILE.name,)+\ + '''Default: %s Supported profiles: ''')%(PRS500_PROFILE.name,)+\ ', '.join(profiles)) page.add_option('--left-margin', default=20, dest='left_margin', type='int', - help='''Left margin of page. Default is %default px.''') + help=_('''Left margin of page. Default is %default px.''')) page.add_option('--right-margin', default=20, dest='right_margin', type='int', - help='''Right margin of page. Default is %default px.''') + help=_('''Right margin of page. Default is %default px.''')) page.add_option('--top-margin', default=10, dest='top_margin', type='int', - help='''Top margin of page. Default is %default px.''') + help=_('''Top margin of page. Default is %default px.''')) page.add_option('--bottom-margin', default=0, dest='bottom_margin', type='int', - help='''Bottom margin of page. Default is %default px.''') + help=_('''Bottom margin of page. Default is %default px.''')) link = parser.add_option_group('LINK PROCESSING OPTIONS') link.add_option('--link-levels', action='store', type='int', default=sys.maxint, \ dest='link_levels', - help=r'''The maximum number of levels to recursively process ''' + help=_(r'''The maximum number of levels to recursively process ''' '''links. A value of 0 means thats links are not followed. ''' - '''A negative value means that tags are ignored.''') + '''A negative value means that tags are ignored.''')) link.add_option('--link-exclude', dest='link_exclude', default='@', - help='''A regular expression. tags whoose href ''' - '''matches will be ignored. Defaults to %default''') + help=_('''A regular expression. tags whoose href ''' + '''matches will be ignored. Defaults to %default''')) chapter = parser.add_option_group('CHAPTER OPTIONS') chapter.add_option('--disable-chapter-detection', action='store_true', default=False, dest='disable_chapter_detection', - help='''Prevent html2lrf from automatically inserting page breaks''' - ''' before what it thinks are chapters.''') + help=_('''Prevent the automatic insertion of page breaks''' + ''' before detected chapters.''')) chapter.add_option('--chapter-regex', dest='chapter_regex', default='chapter|book|appendix', - help='''The regular expression used to detect chapter titles.''' - ''' It is searched for in heading tags (h1-h6). Defaults to %default''') + help=_('''The regular expression used to detect chapter titles.''' + ''' It is searched for in heading tags (h1-h6). Defaults to %default''')) chapter.add_option('--page-break-before-tag', dest='page_break', default='h[12]', - help='''If html2lrf does not find any page breaks in the ''' + help=_('''If html2lrf does not find any page breaks in the ''' '''html file and cannot detect chapter headings, it will ''' '''automatically insert page-breaks before the tags whose ''' '''names match this regular expression. Defaults to %default. ''' @@ -178,36 +179,36 @@ def option_parser(usage): '''The purpose of this option is to try to ensure that ''' '''there are no really long pages as this degrades the page ''' '''turn performance of the LRF. Thus this option is ignored ''' - '''if the current page has only a few elements.''') + '''if the current page has only a few elements.''')) chapter.add_option('--force-page-break-before-tag', dest='force_page_break', - default='$', help='Force a page break before tags whoose names match this regular expression.') + default='$', help=_('Force a page break before tags whoose names match this regular expression.')) chapter.add_option('--force-page-break-before-attr', dest='force_page_break_attr', - default='$,,$', help='Force a page break before an element having the specified attribute. The format for this option is tagname regexp,attribute name,attribute value regexp. For example to match all heading tags that have the attribute class="chapter" you would use "h\d,class,chapter". Default is %default''') + default='$,,$', help=_('Force a page break before an element having the specified attribute. The format for this option is tagname regexp,attribute name,attribute value regexp. For example to match all heading tags that have the attribute class="chapter" you would use "h\d,class,chapter". Default is %default''')) prepro = parser.add_option_group('PREPROCESSING OPTIONS') prepro.add_option('--baen', action='store_true', default=False, dest='baen', - help='''Preprocess Baen HTML files to improve generated LRF.''') + help=_('''Preprocess Baen HTML files to improve generated LRF.''')) prepro.add_option('--pdftohtml', action='store_true', default=False, dest='pdftohtml', - help='''You must add this option if processing files generated by pdftohtml, otherwise conversion will fail.''') + help=_('''You must add this option if processing files generated by pdftohtml, otherwise conversion will fail.''')) prepro.add_option('--book-designer', action='store_true', default=False, dest='book_designer', - help='''Use this option on html0 files from Book Designer.''') + help=_('''Use this option on html0 files from Book Designer.''')) fonts = parser.add_option_group('FONT FAMILIES', - '''Specify trutype font families for serif, sans-serif and monospace fonts. ''' + _('''Specify trutype font families for serif, sans-serif and monospace fonts. ''' '''These fonts will be embedded in the LRF file. Note that custom fonts lead to ''' '''slower page turns. Each family specification is of the form: ''' '''"path to fonts directory, family" ''' '''For example: ''' '''--serif-family "%s, Times New Roman" - ''' % ('C:\Windows\Fonts' if iswindows else '/usr/share/fonts/corefonts')) + ''') % ('C:\Windows\Fonts' if iswindows else '/usr/share/fonts/corefonts')) fonts.add_option('--serif-family', action='callback', callback=font_family, default=None, dest='serif_family', type='string', - help='The serif family of fonts to embed') + help=_('The serif family of fonts to embed')) fonts.add_option('--sans-family', action='callback', callback=font_family, default=None, dest='sans_family', type='string', - help='The sans-serif family of fonts to embed') + help=_('The sans-serif family of fonts to embed')) fonts.add_option('--mono-family', action='callback', callback=font_family, default=None, dest='mono_family', type='string', - help='The monospace family of fonts to embed') + help=_('The monospace family of fonts to embed')) debug = parser.add_option_group('DEBUG OPTIONS') debug.add_option('--verbose', dest='verbose', action='store_true', default=False, diff --git a/src/libprs500/ebooks/lrf/any/convert_from.py b/src/libprs500/ebooks/lrf/any/convert_from.py index 00e4b1dd28..36fa2868ec 100644 --- a/src/libprs500/ebooks/lrf/any/convert_from.py +++ b/src/libprs500/ebooks/lrf/any/convert_from.py @@ -30,8 +30,8 @@ def largest_file(files): for f in files: size = os.stat(f).st_size if size > maxsize: - maxsize = size - file = f + maxsize = size + file = f return file def find_htmlfile(dir): @@ -105,13 +105,13 @@ def process_file(path, options, logger=None): if 'htm' in ext: convertor = html2lrf elif 'lit' == ext: - convertor = lit2lrf + convertor = lit2lrf elif 'pdf' == ext: - convertor = pdf2lrf + convertor = pdf2lrf elif 'rtf' == ext: - convertor = rtf2lrf + convertor = rtf2lrf elif 'txt' == ext: - convertor = txt2lrf + convertor = txt2lrf if not convertor: raise UnknownFormatError('Coverting from %s to LRF is not supported.') convertor(path, options, logger) @@ -123,6 +123,9 @@ def process_file(path, options, logger=None): def main(args=sys.argv, logger=None): + from libprs500 import set_translator + set_translator() + parser = option_parser('''\ any2lrf myfile diff --git a/src/libprs500/ebooks/lrf/html/convert_from.py b/src/libprs500/ebooks/lrf/html/convert_from.py index f33d3b713c..95978c4aee 100644 --- a/src/libprs500/ebooks/lrf/html/convert_from.py +++ b/src/libprs500/ebooks/lrf/html/convert_from.py @@ -1753,7 +1753,9 @@ def option_parser(): return lrf_option_parser('''Usage: %prog [options] mybook.html\n\n''' '''%prog converts mybook.html to mybook.lrf''') -def main(args=sys.argv): +def main(args=sys.argv): + from libprs500 import set_translator + set_translator() try: parser = option_parser() options, args = parser.parse_args(args) diff --git a/src/libprs500/ebooks/lrf/lit/convert_from.py b/src/libprs500/ebooks/lrf/lit/convert_from.py index 8e75bed56e..43de641bb6 100644 --- a/src/libprs500/ebooks/lrf/lit/convert_from.py +++ b/src/libprs500/ebooks/lrf/lit/convert_from.py @@ -96,6 +96,9 @@ def process_file(path, options, logger=None): def main(args=sys.argv, logger=None): + from libprs500 import set_translator + set_translator() + parser = option_parser() options, args = parser.parse_args(args) if len(args) != 2: diff --git a/src/libprs500/ebooks/lrf/meta.py b/src/libprs500/ebooks/lrf/meta.py index cbaa157df1..fd7ca354a7 100644 --- a/src/libprs500/ebooks/lrf/meta.py +++ b/src/libprs500/ebooks/lrf/meta.py @@ -588,34 +588,37 @@ def option_parser(): version=__appname__+' '+__version__, epilog='Created by Kovid Goyal') parser.add_option("-t", "--title", action="store", type="string", \ - dest="title", help="Set the book title") + dest="title", help=_("Set the book title")) parser.add_option('--title-sort', action='store', type='string', default=None, - dest='title_reading', help='Set sort key for the title') + dest='title_reading', help=_('Set sort key for the title')) parser.add_option("-a", "--author", action="store", type="string", \ - dest="author", help="Set the author") + dest="author", help=_("Set the author")) parser.add_option('--author-sort', action='store', type='string', default=None, - dest='author_reading', help='Set sort key for the author') + dest='author_reading', help=_('Set sort key for the author')) parser.add_option("-c", "--category", action="store", type="string", \ - dest="category", help="The category this book belongs"+\ - " to. E.g.: History") + dest="category", help=_("The category this book belongs"+\ + " to. E.g.: History")) parser.add_option("--thumbnail", action="store", type="string", \ - dest="thumbnail", help="Path to a graphic that will be"+\ - " set as this files' thumbnail") + dest="thumbnail", help=_("Path to a graphic that will be"+\ + " set as this files' thumbnail")) parser.add_option("--comment", action="store", type="string", \ - dest="comment", help="Path to a txt file containing the "+\ - "comment to be stored in the lrf file.") + dest="comment", help=_("Path to a txt file containing the "+\ + "comment to be stored in the lrf file.")) parser.add_option("--get-thumbnail", action="store_true", \ dest="get_thumbnail", default=False, \ - help="Extract thumbnail from LRF file") + help=_("Extract thumbnail from LRF file")) parser.add_option('--bookid', action='store', type='string', default=None, - dest='book_id', help='Set book ID') + dest='book_id', help=_('Set book ID')) parser.add_option("-p", "--page", action="store", type="string", \ - dest="page", help="Don't know what this is for") + dest="page", help=_("Don't know what this is for")) return parser def main(args=sys.argv): + from libprs500 import set_translator + set_translator() + import os.path parser = option_parser() options, args = parser.parse_args(args) diff --git a/src/libprs500/ebooks/lrf/pdf/convert_from.py b/src/libprs500/ebooks/lrf/pdf/convert_from.py index 194f2d27e7..da8a17a17a 100644 --- a/src/libprs500/ebooks/lrf/pdf/convert_from.py +++ b/src/libprs500/ebooks/lrf/pdf/convert_from.py @@ -77,6 +77,9 @@ def process_file(path, options, logger=None): def main(args=sys.argv, logger=None): + from libprs500 import set_translator + set_translator() + parser = option_parser() options, args = parser.parse_args(args) if len(args) != 2: diff --git a/src/libprs500/ebooks/lrf/rtf/convert_from.py b/src/libprs500/ebooks/lrf/rtf/convert_from.py index b54e107a91..0fa76f3067 100644 --- a/src/libprs500/ebooks/lrf/rtf/convert_from.py +++ b/src/libprs500/ebooks/lrf/rtf/convert_from.py @@ -100,6 +100,9 @@ def process_file(path, options, logger=None): shutil.rmtree(tdir) def main(args=sys.argv, logger=None): + from libprs500 import set_translator + set_translator() + parser = option_parser() options, args = parser.parse_args(args) if len(args) != 2: diff --git a/src/libprs500/ebooks/lrf/txt/convert_from.py b/src/libprs500/ebooks/lrf/txt/convert_from.py index b7fecd92ec..0c1fbe164d 100644 --- a/src/libprs500/ebooks/lrf/txt/convert_from.py +++ b/src/libprs500/ebooks/lrf/txt/convert_from.py @@ -93,6 +93,9 @@ def process_file(path, options, logger=None): print open(htmlfile.name, 'rb').read() def main(args=sys.argv, logger=None): + from libprs500 import set_translator + set_translator() + parser = option_parser() options, args = parser.parse_args(args) if len(args) != 2: diff --git a/src/libprs500/ebooks/lrf/web/convert_from.py b/src/libprs500/ebooks/lrf/web/convert_from.py index fdcc34f10f..a47a994b19 100644 --- a/src/libprs500/ebooks/lrf/web/convert_from.py +++ b/src/libprs500/ebooks/lrf/web/convert_from.py @@ -147,6 +147,9 @@ def process_profile(args, options, logger=None): def main(args=sys.argv, logger=None): + from libprs500 import set_translator + set_translator() + parser = option_parser() options, args = parser.parse_args(args) if len(args) > 2: diff --git a/src/libprs500/ebooks/metadata/isbndb.py b/src/libprs500/ebooks/metadata/isbndb.py index 59a6132ca1..2bdb7e12be 100644 --- a/src/libprs500/ebooks/metadata/isbndb.py +++ b/src/libprs500/ebooks/metadata/isbndb.py @@ -130,6 +130,9 @@ def create_books(opts, args, logger=None): return [ISBNDBMetadata(book) for book in fetch_metadata(url)] def main(args=sys.argv): + from libprs500 import set_translator + set_translator() + parser = option_parser() opts, args = parser.parse_args(args) if len(args) != 2: diff --git a/src/libprs500/ebooks/metadata/pdf.py b/src/libprs500/ebooks/metadata/pdf.py index 18e32a258d..5f31e2b88e 100644 --- a/src/libprs500/ebooks/metadata/pdf.py +++ b/src/libprs500/ebooks/metadata/pdf.py @@ -46,6 +46,9 @@ def get_metadata(stream): def main(args=sys.argv): + from libprs500 import set_translator + set_translator() + if len(args) != 2: print >>sys.stderr, 'Usage: pdf-meta file.pdf' print >>sys.stderr, 'No filename specified.' diff --git a/src/libprs500/ebooks/metadata/rtf.py b/src/libprs500/ebooks/metadata/rtf.py index e617e33feb..81ea68ac0a 100644 --- a/src/libprs500/ebooks/metadata/rtf.py +++ b/src/libprs500/ebooks/metadata/rtf.py @@ -174,6 +174,9 @@ def set_metadata(stream, options): def main(args=sys.argv): + from libprs500 import set_translator + set_translator() + parser = get_parser('rtf') options, args = parser.parse_args(args) if len(args) != 2: diff --git a/src/libprs500/gui2/__init__.py b/src/libprs500/gui2/__init__.py index 18f75dd443..c43e349ca4 100644 --- a/src/libprs500/gui2/__init__.py +++ b/src/libprs500/gui2/__init__.py @@ -15,13 +15,14 @@ """ The GUI for libprs500. """ import sys, os, re, StringIO, traceback from PyQt4.QtCore import QVariant, QSettings, QFileInfo, QObject, SIGNAL, QBuffer, \ - QByteArray + QByteArray, QLocale, QTranslator from PyQt4.QtGui import QFileDialog, QMessageBox, QPixmap, QFileIconProvider, \ QIcon, QTableView ORG_NAME = 'KovidsBrain' APP_UID = 'libprs500' from libprs500 import __author__, islinux +from libprs500.gui2.translations import translations NONE = QVariant() #: Null value to return from the data function of item models BOOK_EXTENSIONS = ['lrf', 'lrx', 'rar', 'zip', 'rtf', 'lit', 'txt', 'htm', @@ -297,4 +298,17 @@ def pixmap_to_data(pixmap, format='JPEG'): buf.open(QBuffer.WriteOnly) pixmap.save(buf, format) return str(ba.data()) + +def set_translator(app): + locale = QLocale.system().language() + locale = 'test' + if translations.has_key(locale): + data = translations[locale] + t = QTranslator() + open('yay.qm', 'wb').write(data) + t.load('yay.qm') + print t.isEmpty() + app.installTranslator(t) + os.unlink('yay.qm') + \ No newline at end of file diff --git a/src/libprs500/gui2/dialogs/conversion_error.py b/src/libprs500/gui2/dialogs/conversion_error.py index 579f832102..10b343b5db 100644 --- a/src/libprs500/gui2/dialogs/conversion_error.py +++ b/src/libprs500/gui2/dialogs/conversion_error.py @@ -12,8 +12,6 @@ ## You should have received a copy of the GNU General Public License along ## with this program; if not, write to the Free Software Foundation, Inc., ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -'''''' - from PyQt4.QtGui import QDialog from libprs500.gui2.dialogs.conversion_error_ui import Ui_ConversionErrorDialog diff --git a/src/libprs500/gui2/lrf_renderer/__init__.py b/src/libprs500/gui2/lrf_renderer/__init__.py index decc037eb2..24c4e11424 100644 --- a/src/libprs500/gui2/lrf_renderer/__init__.py +++ b/src/libprs500/gui2/lrf_renderer/__init__.py @@ -12,5 +12,5 @@ ## You should have received a copy of the GNU General Public License along ## with this program; if not, write to the Free Software Foundation, Inc., ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -'''''' + diff --git a/src/libprs500/gui2/lrf_renderer/document.py b/src/libprs500/gui2/lrf_renderer/document.py index 51cdaadf5e..3677bf4bbd 100644 --- a/src/libprs500/gui2/lrf_renderer/document.py +++ b/src/libprs500/gui2/lrf_renderer/document.py @@ -12,8 +12,6 @@ ## You should have received a copy of the GNU General Public License along ## with this program; if not, write to the Free Software Foundation, Inc., ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -'''''' - import collections, itertools from PyQt4.QtCore import Qt, QByteArray, SIGNAL diff --git a/src/libprs500/gui2/lrf_renderer/main.py b/src/libprs500/gui2/lrf_renderer/main.py index 8f7428f628..426735418a 100644 --- a/src/libprs500/gui2/lrf_renderer/main.py +++ b/src/libprs500/gui2/lrf_renderer/main.py @@ -12,10 +12,7 @@ ## You should have received a copy of the GNU General Public License along ## with this program; if not, write to the Free Software Foundation, Inc., ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -from libprs500.gui2 import choose_files -'''''' - -import sys, logging, os, traceback, time, cPickle, copy +import sys, logging, os, traceback, time, cPickle from PyQt4.QtGui import QApplication, QKeySequence, QPainter, QDialog from PyQt4.QtCore import Qt, QObject, SIGNAL, QCoreApplication, QThread, \ @@ -24,7 +21,7 @@ from PyQt4.QtCore import Qt, QObject, SIGNAL, QCoreApplication, QThread, \ from libprs500 import __appname__, __version__, __author__, setup_cli_handlers, islinux from libprs500.ebooks.lrf.parser import LRFDocument -from libprs500.gui2 import ORG_NAME, APP_UID, error_dialog +from libprs500.gui2 import ORG_NAME, APP_UID, error_dialog, choose_files from libprs500.gui2.dialogs.conversion_error import ConversionErrorDialog from libprs500.gui2.lrf_renderer.main_ui import Ui_MainWindow from libprs500.gui2.lrf_renderer.config_ui import Ui_ViewerConfig @@ -285,6 +282,8 @@ def normalize_settings(parser, opts): def main(args=sys.argv, logger=None): + from libprs500 import set_translator + set_translator() parser = option_parser() opts, args = parser.parse_args(args) if hasattr(opts, 'help'): diff --git a/src/libprs500/gui2/lrf_renderer/text.py b/src/libprs500/gui2/lrf_renderer/text.py index c10637d82d..b4980fd0ce 100644 --- a/src/libprs500/gui2/lrf_renderer/text.py +++ b/src/libprs500/gui2/lrf_renderer/text.py @@ -12,8 +12,6 @@ ## You should have received a copy of the GNU General Public License along ## with this program; if not, write to the Free Software Foundation, Inc., ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -'''''' - import sys, collections, operator, copy, re from PyQt4.QtCore import Qt, QRectF, QString diff --git a/src/libprs500/gui2/main.py b/src/libprs500/gui2/main.py index 3d68a84f61..f5ee7042d0 100644 --- a/src/libprs500/gui2/main.py +++ b/src/libprs500/gui2/main.py @@ -20,7 +20,7 @@ from PyQt4.QtGui import QPixmap, QColor, QPainter, QMenu, QIcon, QMessageBox, \ QToolButton, QDialog from PyQt4.QtSvg import QSvgRenderer -from libprs500 import __version__, __appname__, islinux +from libprs500 import __version__, __appname__, islinux, set_translator from libprs500.ptempfile import PersistentTemporaryFile from libprs500.ebooks.metadata.meta import get_metadata from libprs500.ebooks.lrf.web.convert_from import main as web2lrf @@ -716,12 +716,13 @@ class Main(MainWindow, Ui_MainWindow): def main(args=sys.argv): + set_translator() from PyQt4.Qt import QApplication pid = os.fork() if islinux else -1 if pid <= 0: app = QApplication(args) QCoreApplication.setOrganizationName(ORG_NAME) - QCoreApplication.setApplicationName(APP_UID) + QCoreApplication.setApplicationName(APP_UID) initialize_file_icon_provider() try: main = Main() diff --git a/src/libprs500/gui2/main.ui b/src/libprs500/gui2/main.ui index 5fcdff4b17..a2f1cb761f 100644 --- a/src/libprs500/gui2/main.ui +++ b/src/libprs500/gui2/main.ui @@ -105,7 +105,7 @@ <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">For help visit <a href="https://libprs500.kovidgoyal.net/wiki/WikiStart#Usage">libprs500.kovidgoyal.net</a><br /><br /><span style=" font-weight:600;">libprs500</span>: %1 by <span style=" font-weight:600;">Kovid Goyal</span> © 2007<br />%2</p></body></html> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">For help visit <a href="https://libprs500.kovidgoyal.net/wiki/WikiStart#Usage"><span style=" text-decoration: underline; color:#0000ff;">libprs500.kovidgoyal.net</span></a><br /><br /><span style=" font-weight:600;">libprs500</span>: %1 by <span style=" font-weight:600;">Kovid Goyal</span> <br />%2</p></body></html> Qt::RichText diff --git a/src/libprs500/gui2/make.py b/src/libprs500/gui2/make.py index 02850a2906..35a189937f 100644 --- a/src/libprs500/gui2/make.py +++ b/src/libprs500/gui2/make.py @@ -16,7 +16,7 @@ Manage the PyQt build system pyrcc4, pylupdate4, lrelease and friends. ''' -import sys, os, subprocess, cStringIO, compiler +import sys, os, subprocess, cStringIO, compiler, re from functools import partial from PyQt4.uic import compileUi @@ -45,11 +45,13 @@ def build_forms(forms): dat = buf.getvalue() dat = dat.replace('import images_rc', 'from libprs500.gui2 import images_rc') dat = dat.replace('from library import', 'from libprs500.gui2.library import') + dat = re.compile(r'QtGui.QApplication.translate\(.+?,\s+"(.+?)(?