From: John Mandereau Date: Thu, 22 Feb 2007 21:56:08 +0000 (+0100) Subject: Improve doc translation infrastructure X-Git-Tag: release/2.10.20-1~13 X-Git-Url: https://git.donarmstrong.com/lilypond.git?a=commitdiff_plain;h=fbc04dd7c7f25c853546fdacd7f36da3c4258b27;p=lilypond.git Improve doc translation infrastructure Add support for automatic Texinfo skeletons update Usage: make -C Documentation ISOLANG=mylang skeleton-update --- diff --git a/Documentation/GNUmakefile b/Documentation/GNUmakefile index ec7826a07b..8b13a9a6ab 100644 --- a/Documentation/GNUmakefile +++ b/Documentation/GNUmakefile @@ -29,6 +29,9 @@ OUT_TXT_FILES = $(addprefix $(outdir)/, $(addsuffix .txt, $(README_TOP_FILES))) txt-to-html: $(PYTHON) $(step-bindir)/text2html.py $(OUT_TXT_FILES) +po-update: + make -C po po-update + ifneq ($(ISOLANG),) new-lang: @if (( $$(file -b $(ISOLANG)) == directory )) 2>/dev/null; \ @@ -39,7 +42,7 @@ new-lang: cp fr/GNUmakefile $(ISOLANG) cp fr/user/GNUmakefile $(ISOLANG)/user sed -i -e 's/ISOLANG *= *fr/ISOLANG = $(ISOLANG)/' $(ISOLANG)/GNUmakefile $(ISOLANG)/user/GNUmakefile - $(PYTHON) $(buildscript-dir)/texi-langutils.py -d $(outdir) -b "UNTRANSLATED NODE: IGNORE ME" -o doc.pot --skeleton --gettext ../user/lilypond.tely + $(PYTHON) $(buildscript-dir)/texi-langutils.py -d $(outdir) -b "UNTRANSLATED NODE: IGNORE ME" -l $(ISOLANG) -o doc.pot --skeleton --gettext ../user/lilypond.tely mv $(outdir)/*.*tely $(ISOLANG)/user msgmerge -U po/lilypond-doc.pot $(outdir)/doc.pot cp po/lilypond-doc.pot po/$(ISOLANG).po @@ -47,4 +50,8 @@ new-lang: check-translation: find $(ISOLANG)/user/ -name '*.*tely' | xargs $(PYTHON) $(buildscript-dir)/check_translation.py $(buildscript-dir) + +skeleton-update: + $(PYTHON) $(buildscript-dir)/texi-langutils.py -d $(outdir) -b "UNTRANSLATED NODE: IGNORE ME" -l $(ISOLANG) --skeleton ../user/lilypond.tely + $(PYTHON) $(buildscript-dir)/texi-skeleton-update.py $(ISOLANG)/user $(outdir) endif diff --git a/buildscripts/texi-langutils.py b/buildscripts/texi-langutils.py index b2fbe5f832..8fc24187de 100644 --- a/buildscripts/texi-langutils.py +++ b/buildscripts/texi-langutils.py @@ -7,9 +7,17 @@ import sys import re import getopt import os -import string -optlist, texi_files = getopt.getopt(sys.argv[1:],'no:d:b:i:',['skeleton', 'gettext']) +def read_pipe (command): + print command + pipe = os.popen (command) + output = pipe.read () + if pipe.close (): + print "pipe failed: %(command)s" % locals () + return output + + +optlist, texi_files = getopt.getopt(sys.argv[1:],'no:d:b:i:l:',['skeleton', 'gettext']) process_includes = not ('-n', '') in optlist # -n don't process @include's in texinfo files make_gettext = ('--gettext', '') in optlist # --gettext generate a node list from a Texinfo source @@ -17,7 +25,24 @@ make_skeleton = ('--skeleton', '') in optlist # --skeleton extract the node tr output_file = 'doc.pot' node_blurb = '' -intro_blurb = '' +doclang = '' +topfile = os.path.basename (texi_files[0]) +head_committish = read_pipe ('git-rev-parse HEAD') +intro_blurb = '''@c -*- coding: utf-8; mode: texinfo%(doclang)s -*- +@c This file is part of %(topfile)s +@ignore + Translation of GIT committish: %(head_committish)s + + When revising a translation, copy the HEAD committish of the + version that you are working on. See TRANSLATION for details. +@end ignore +''' + +end_blurb = """ +-- SKELETON FILE -- +When you actually translate this file, please remove these lines as +well as all `UNTRANSLATED NODE: IGNORE ME' lines. +""" for x in optlist: if x[0] == '-o': # -o NAME set PO output file name to NAME @@ -28,6 +53,12 @@ for x in optlist: node_blurb = x[1] elif x[0] == '-i': # -i BLURB set blurb written at beginning of each file to BLURB intro_blurb = x[1] + elif x[0] == '-l': # -l ISOLANG set documentlanguage to ISOLANG + doclang = '; documentlanguage: ' + x[1] + + +intro_blurb = intro_blurb % vars() + def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, output_file=None): try: @@ -58,9 +89,11 @@ def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, output_file=No if output_file: output_file.write ('_("' + item[3].strip () + '") # @' + item[2] + \ ' in ' + texifilename + '\n') - node_trigger = True + if item[2] == 'node': + node_trigger = True elif item[2] == 'include': includes.append(item[3]) + g.write (end_blurb) g.close () elif output_file: toto = re.findall (r"""^@(include|node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading) *([^ diff --git a/buildscripts/texi-skeleton-update.py b/buildscripts/texi-skeleton-update.py new file mode 100644 index 0000000000..a2a5df3ccd --- /dev/null +++ b/buildscripts/texi-skeleton-update.py @@ -0,0 +1,25 @@ +#!@PYTHON@ +# texi-skeleton-update.py + +import sys +import glob +import os +import shutil + +sys.stderr.write ('texi-skeleton-update.py\n') + +orig_skeletons = set ([os.path.basename (f) for f in glob.glob (sys.argv[1] + '/*.itely')]) +new_skeletons = set ([os.path.basename (f) for f in glob.glob (sys.argv[2] + '/*.itely')]) + +for f in new_skeletons: + if f in orig_skeletons: + g = open (os.path.join (sys.argv[1], f), 'r').read () + if '-- SKELETON FILE --' in g: + sys.stderr.write ("Copying %s...\n" % f) + shutil.copy (os.path.join (sys.argv[2], f), sys.argv[1]) + else: + sys.stderr.write ("Copying new file %s...\n" % f) + shutil.copy (os.path.join (sys.argv[2], f), sys.argv[1]) + +for f in orig_skeletons.difference (new_skeletons): + sys.stderr.write ("Warning: outdated skeleton file %s\n" % f)