]> git.donarmstrong.com Git - lilypond.git/blobdiff - buildscripts/texi-langutils.py
Change Info docs setup and clean up Documentation/user/GNUmakefile
[lilypond.git] / buildscripts / texi-langutils.py
index 09737639b7834523bbc14e377e3b355cb7951535..a2d8958f569ccca6d998bb627de609e41f8f987a 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,22 @@ make_skeleton = ('--skeleton', '') in optlist # --skeleton   extract the node tr
 
 output_file = 'doc.pot'
 node_blurb = ''
-intro_blurb = ''
+doclang = ''
+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,26 +51,32 @@ 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]
+
 
-def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, output_file=None):
+def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, topfile, output_file=None):
        try:
-               #print "Processing %s..." % texifilename
                f = open (texifilename, 'r')
                texifile = f.read ()
                f.close ()
                includes = []
                if write_skeleton:
                        g = open (os.path.basename (texifilename), 'w')
-                       g.write (i_blurb)
+                        subst = globals ()
+                        subst.update (locals ())
+                       g.write (i_blurb % subst)
                        tutu = re.findall (r"""^(\*) +([^:
                        ]+)::[^
-                       ]*?$|^@(include|menu|end menu|node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading) *([^@
+                       ]*?$|^@(include|menu|end menu|node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading) *([^
                        ]*)[^
-                       ]*?$""", texifile, re.M)
+                       ]*?$|@(rglos){(.+?)}""", texifile, re.M)
                        node_trigger = False
                        for item in tutu:
                                if item[0] == '*':
                                        g.write ('* ' + item[1] + '::\n')
+                               elif output_file and item[4] == 'rglos':
+                                       output_file.write ('_(r"' + item[5] + '") # @rglos in ' + texifilename + '\n')
                                else:
                                        g.write ('@' + item[2] + ' ' + item[3] + '\n')
                                        if node_trigger:
@@ -55,24 +84,29 @@ def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, output_file=No
                                                node_trigger = False
                                        if not item[2] in ('include', 'menu', 'end menu'):
                                                if output_file:
-                                                       output_file.write ('_("' + item[3].strip () + '")\n')
-                                               node_trigger = True
+                                                       output_file.write ('_(r"' + item[3].strip () + '") # @' + item[2] + \
+                                                                          ' in ' + texifilename + '\n')
+                                               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) *([^@
+                       toto = re.findall (r"""^@(include|node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading) *([^
                        ]*)[^
-                       ]*?$""", texifile, re.M)
+                       ]*?$|@(rglos){(.+?)}""", texifile, re.M)
                        for item in toto:
                                if item[0] == 'include':
                                        includes.append(item[1])
+                               elif item[2] == 'rglos':
+                                       output_file.write ('# @rglos in ' + texifilename + '\n_(r"' + item[3] + '")\n')
                                else:
-                                       output_file.write ('_("' + item[1].strip () + '")\n')
+                                       output_file.write ('# @' + item[0] + ' in ' + texifilename + '\n_(r"' + item[1].strip () + '")\n')
                if process_includes:
                        dir = os.path.dirname (texifilename)
                        for item in includes:
-                               process_texi (os.path.join (dir, item.strip ()), i_blurb, n_blurb, write_skeleton, output_file)
+                               process_texi (os.path.join (dir, item.strip ()), i_blurb, n_blurb, write_skeleton, topfile, output_file)
        except IOError, (errno, strerror):
                print "I/O error(%s): %s: %s" % (errno, texifilename, strerror)
 
@@ -84,12 +118,13 @@ if node_blurb != '':
 if make_gettext:
        node_list_filename = 'node_list'
        node_list = open (node_list_filename, 'w')
+       node_list.write ('# -*- coding: utf-8 -*-\n')
        for texi_file in texi_files:
-               process_texi (texi_file, intro_blurb, node_blurb, make_skeleton, node_list)
-       for word in ('Up:', 'Next:', 'Previous:', 'Appendix'):
-               node_list.write ('_("' + word + '")\n')
+               process_texi (texi_file, intro_blurb, node_blurb, make_skeleton, os.path.basename (texi_file), node_list)
+       for word in ('Up:', 'Next:', 'Previous:', 'Appendix ', 'Footnotes', 'Table of Contents'):
+               node_list.write ('_(r"' + word + '")\n')
        node_list.close ()
-       os.system ('xgettext -L Python --no-location -o ' + output_file + ' ' + node_list_filename)
+       os.system ('xgettext -c -L Python --no-location -o ' + output_file + ' ' + node_list_filename)
 else:
        for texi_file in texi_files:
-               process_texi (texi_file, intro_blurb, node_blurb, make_skeleton)
+               process_texi (texi_file, intro_blurb, node_blurb, make_skeleton, os.path.basename (texi_file))