]> git.donarmstrong.com Git - lilypond.git/commitdiff
Improve doc translation infrastructure
authorJohn Mandereau <john.mandereau@gmail.com>
Thu, 22 Feb 2007 21:56:08 +0000 (22:56 +0100)
committerJohn Mandereau <john.mandereau@gmail.com>
Thu, 22 Feb 2007 21:56:08 +0000 (22:56 +0100)
Add support for automatic Texinfo skeletons update
Usage: make -C Documentation ISOLANG=mylang skeleton-update

Documentation/GNUmakefile
buildscripts/texi-langutils.py
buildscripts/texi-skeleton-update.py [new file with mode: 0644]

index cd96e38b5b61630c6bf3404be337826b59136442..2b5940745ca9f0659eec7c809db3c5682372176c 100644 (file)
@@ -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
index 9f914008f79fcce5dddf38bbb1ccc83885c2769b..02b0ea36fa683683f8df22d5e0756eae62af0f16 100644 (file)
@@ -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 (file)
index 0000000..a2a5df3
--- /dev/null
@@ -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)