X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=buildscripts%2Ftexi-langutils.py;h=844e2ef86817637c8c00461838884b2b731bbbce;hb=f85b403073143dc7ebb84ed193ebee2b0a2b1bd3;hp=33f130d1587ba19e7bd0c17f0bf5d7e0f59409e8;hpb=e34621159931fdbc7dff10973c2bc9ca38ab024c;p=lilypond.git diff --git a/buildscripts/texi-langutils.py b/buildscripts/texi-langutils.py index 33f130d158..844e2ef868 100644 --- a/buildscripts/texi-langutils.py +++ b/buildscripts/texi-langutils.py @@ -26,9 +26,9 @@ make_gettext = ('--gettext', '') in optlist # --gettext generate a node lis make_skeleton = ('--skeleton', '') in optlist # --skeleton extract the node tree from a Texinfo source output_file = 'doc.pot' -node_blurb = '''@ifhtml -UNTRANSLATED NODE: IGNORE ME -@end ifhtml + +# @untranslated should be defined as a macro in Texinfo source +node_blurb = '''@untranslated ''' doclang = '' head_committish = read_pipe ('git-rev-parse HEAD') @@ -57,14 +57,14 @@ for x in optlist: elif x[0] == '-l': # -l ISOLANG set documentlanguage to ISOLANG doclang = '; documentlanguage: ' + x[1] -texinfo_with_menus_re = re.compile (r"^(\*) +([^:\n]+)::.*?$|^@(include|menu|end menu|node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading) *(.+?)$|@(rglos){(.+?)}", re.M) +texinfo_with_menus_re = re.compile (r"^(\*) +([^:\n]+)::.*?$|^@(include|menu|end menu|node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading) *(.*?)$|@(rglos){(.+?)}", re.M) texinfo_re = re.compile (r"^@(include|node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading) *(.+?)$|@(rglos){(.+?)}", re.M) ly_string_re = re.compile (r'^([a-zA-Z]+)[\t ]*=|%+[\t ]*(.*)$') verbatim_ly_re = re.compile (r'@lilypond\[.*?verbatim') -def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, topfile, output_file=None): +def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, topfile, output_file=None, scan_ly=False): try: f = open (texifilename, 'r') texifile = f.read () @@ -73,7 +73,7 @@ def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, topfile, outpu includes = [] # process ly var names and comments - if output_file: + if output_file and scan_ly: lines = texifile.splitlines () i = 0 in_verb_ly_block = False @@ -104,19 +104,23 @@ def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, topfile, outpu g.write ('* ' + item[1] + '::\n') elif output_file and item[4] == 'rglos': output_file.write ('_(r"' + item[5] + '") # @rglos in ' + printedfilename + '\n') + elif item[2] == 'menu': + g.write ('@menu\n') + elif item[2] == 'end menu': + g.write ('@end menu\n\n') else: g.write ('@' + item[2] + ' ' + item[3] + '\n') if node_trigger: g.write (n_blurb) node_trigger = False - if not item[2] in ('include', 'menu', 'end menu'): + elif item[2] == 'include': + includes.append (item[3]) + else: if output_file: output_file.write ('# @' + item[2] + ' in ' + \ printedfilename + '\n_(r"' + item[3].strip () + '")\n') if item[2] == 'node': node_trigger = True - elif item[2] == 'include': - includes.append(item[3]) g.write (end_blurb) g.close () @@ -129,12 +133,13 @@ def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, topfile, outpu output_file.write ('# @rglos in ' + printedfilename + '\n_(r"' + item[3] + '")\n') else: output_file.write ('# @' + item[0] + ' in ' + printedfilename + '\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, topfile, output_file) + process_texi (os.path.join (dir, item.strip ()), i_blurb, n_blurb, write_skeleton, topfile, output_file, scan_ly) except IOError, (errno, strerror): - print "I/O error(%s): %s: %s" % (errno, texifilename, strerror) + sys.stderr.write ("I/O error(%s): %s: %s" % (errno, texifilename, strerror)) if intro_blurb != '': @@ -146,11 +151,16 @@ if make_gettext: 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, os.path.basename (texi_file), node_list) + # Urgly: scan ly comments and variable names only in English doco + is_english_doc = 'Documentation/user' in texi_file + process_texi (texi_file, intro_blurb, node_blurb, make_skeleton, + os.path.basename (texi_file), node_list, + scan_ly=is_english_doc) for word in ('Up:', 'Next:', 'Previous:', 'Appendix ', 'Footnotes', 'Table of Contents'): node_list.write ('_(r"' + word + '")\n') node_list.close () 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, os.path.basename (texi_file)) + process_texi (texi_file, intro_blurb, node_blurb, make_skeleton, + os.path.basename (texi_file))