mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Allow running the translations builder on OSes other than linux where msgfmt is not available
This commit is contained in:
parent
7e68c19381
commit
51a6d79039
@ -6,7 +6,7 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__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:
|
||||
|
@ -1,4 +1,4 @@
|
||||
#! /usr/bin/env python2
|
||||
#!/usr/bin/env python2
|
||||
# Written by Martin v. Loewis <loewis@informatik.hu-berlin.de>
|
||||
|
||||
"""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__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user