diff --git a/setup/translations.py b/setup/translations.py index f397b43ce4..f338119b2a 100644 --- a/setup/translations.py +++ b/setup/translations.py @@ -6,7 +6,7 @@ __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import os, tempfile, shutil, subprocess, glob, re, time, textwrap, cPickle, shlex, json, errno, hashlib +import os, tempfile, shutil, subprocess, glob, re, time, textwrap, cPickle, shlex, json, errno, hashlib, sys from collections import defaultdict from locale import normalize as normalize_locale from functools import partial @@ -255,6 +255,7 @@ class Translations(POT): # {{{ self.compile_user_manual_translations() def compile_group(self, files, handle_stats=None, file_ok=None, action_per_file=None): + from calibre.constants import islinux jobs, ok_files = [], [] hashmap = {} @@ -279,7 +280,11 @@ class Translations(POT): # {{{ else: if file_ok is None or file_ok(data, src): self.info('\t' + os.path.relpath(src, self.j(self.d(self.SRC), 'translations'))) - jobs.append(['msgfmt', '--statistics', '-o', dest, src]) + if islinux: + msgfmt = ['msgfmt'] + else: + msgfmt = [sys.executable, self.j(self.SRC, 'calibre', 'translations', 'msgfmt.py')] + jobs.append(msgfmt + ['--statistics', '-o', dest, src]) ok_files.append((src, dest)) hashmap[src] = current_hash if action_per_file is not None: diff --git a/src/calibre/translations/msgfmt.py b/src/calibre/translations/msgfmt.py index aa8e3b806c..eeffc87429 100644 --- a/src/calibre/translations/msgfmt.py +++ b/src/calibre/translations/msgfmt.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python2 +#!/usr/bin/env python2 # Written by Martin v. Loewis """Generate binary message catalog from textual translation description. @@ -33,7 +33,7 @@ import array __version__ = "1.1" MESSAGES = {} - +STATS = {'translated': 0, 'untranslated': 0} def usage(code, msg=''): print >> sys.stderr, __doc__ @@ -45,8 +45,13 @@ def usage(code, msg=''): def add(id, str, fuzzy): "Add a non-fuzzy translation to the dictionary." global MESSAGES + if not id: + return if not fuzzy and str: MESSAGES[id] = str + STATS['translated'] += 1 + else: + STATS['untranslated'] += 1 def generate(): @@ -193,12 +198,13 @@ def make(filename, outfile): def main(): try: - opts, args = getopt.getopt(sys.argv[1:], 'hVo:', - ['help', 'version', 'output-file=']) + opts, args = getopt.getopt(sys.argv[1:], 'hVso:', + ['help', 'version', 'statistics', 'output-file=']) except getopt.error, msg: usage(1, msg) outfile = None + output_stats = False # parse options for opt, arg in opts: if opt in ('-h', '--help'): @@ -208,6 +214,8 @@ def main(): sys.exit(0) elif opt in ('-o', '--output-file'): outfile = arg + elif opt in ('-s', '--statistics'): + output_stats = True # do it if not args: print >> sys.stderr, 'No input file given' @@ -215,7 +223,10 @@ def main(): return for filename in args: + STATS['translated'] = STATS['untranslated'] = 0 make(filename, outfile) + if output_stats: + print STATS['translated'], 'translated messages,', STATS['untranslated'], 'untranslated messages.' if __name__ == '__main__':