X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fauxiliar%2Ftexi-langutils.py;h=a2da780f2619de34fdf3c99ffb5c1d1eefe7b185;hb=HEAD;hp=24cb2ecec9a6f9e69e7127c333228498b6de8f7a;hpb=683f24de2a834aff75e20ad9bc31039893568dea;p=lilypond.git diff --git a/scripts/auxiliar/texi-langutils.py b/scripts/auxiliar/texi-langutils.py index 24cb2ecec9..a2da780f26 100755 --- a/scripts/auxiliar/texi-langutils.py +++ b/scripts/auxiliar/texi-langutils.py @@ -19,11 +19,12 @@ def read_pipe (command): return output -optlist, texi_files = getopt.getopt(sys.argv[1:],'no:d:b:i:l:',['skeleton', 'gettext']) +optlist, texi_files = getopt.getopt(sys.argv[1:],'no:d:b:i:l:',['skeleton', 'gettext', 'head-only']) 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 make_skeleton = ('--skeleton', '') in optlist # --skeleton extract the node tree from a Texinfo source +head_only = ('--head-only', '') in optlist # --head-only only write first node in included Texinfo skeletons output_name = 'doc.pot' @@ -59,7 +60,7 @@ 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]+)::.*?$|^@(afourpaper|author|bye|contents|copying|end copying|divClass|divEnd|divId|documentencoding|documentlanguage|finalout|ifnottex|end ifnottex|imageClickable|imageFloat|imageId|image|include|menu|end menu|node|quotation|end quotation|ref|rgloss|setfilename|settitle|set|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|titlefont|titlepage|end titlepage|title|sourceimage|subtitle|top|vskip|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading|c) *(([^ \n].*)|$)", 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) @@ -67,7 +68,8 @@ ly_string_re = re.compile (r'^([a-zA-Z]+)[\t ]*=|%+[\t ]*(.*)$|\\(?:new|context) lsr_verbatim_ly_re = re.compile (r'% begin verbatim$') texinfo_verbatim_ly_re = re.compile (r'^@lilypond\[.*?verbatim') -def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, topfile, output_file=None, scan_ly=False): +def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, topfile, + output_file=None, scan_ly=False, inclusion_level=0): try: f = open (texifilename, 'r') texifile = f.read () @@ -110,7 +112,7 @@ def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, topfile, outpu subst.update (locals ()) g.write (i_blurb % subst) tutu = texinfo_with_menus_re.findall (texifile) - node_trigger = False + node_just_defined = '' for item in tutu: if item[0] == '*': g.write ('* ' + item[1] + '::\n') @@ -127,9 +129,12 @@ def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, topfile, outpu if item[3].startswith ('{') or not item[3].strip (): space = '' g.write ('@' + item[2] + space + item[3] + '\n') - if node_trigger: + if node_just_defined: + g.write ('@translationof ' + node_just_defined + '\n') g.write (n_blurb) - node_trigger = False + node_just_defined = '' + if head_only and inclusion_level == 1: + break elif item[2] == 'include': includes.append (item[3]) else: @@ -137,11 +142,12 @@ def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, topfile, outpu output_file.write ('# @' + item[2] + ' in ' + \ printedfilename + '\n_(r"' + item[3].strip () + '")\n') if item[2] == 'node': - node_trigger = True - g.write (end_blurb) + node_just_defined = item[3].strip () + if not head_only: + g.write (end_blurb) g.close () - elif output_file: + elif output_file and scan_ly: toto = texinfo_re.findall (texifile) for item in toto: if item[0] == 'include': @@ -149,12 +155,13 @@ def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, topfile, outpu elif item[2] == 'rglos': 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') + output_file.write ('# @' + item[0] + ' in ' + printedfilename + '\n_(r"' + item[1].strip ().replace ('\\', r'\\') + '")\n') - if process_includes: + if process_includes and (not head_only or inclusion_level < 1): 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, scan_ly) + process_texi (os.path.join (dir, item.strip ()), i_blurb, n_blurb, + write_skeleton, topfile, output_file, scan_ly, inclusion_level + 1) except IOError, (errno, strerror): sys.stderr.write ("I/O error(%s): %s: %s\n" % (errno, texifilename, strerror)) @@ -171,12 +178,16 @@ if make_gettext: # Urgly: scan ly comments and variable names only in English doco is_english_doc = ( True + and not 'Documentation/cs/' in texi_file and not 'Documentation/de/' in texi_file and not 'Documentation/es/' in texi_file and not 'Documentation/fr/' in texi_file + and not 'Documentation/hu/' in texi_file and not 'Documentation/ja/' in texi_file + and not 'Documentation/it/' in texi_file and not 'Documentation/nl/' in texi_file and not 'Documentation/po/' in texi_file + and not 'Documentation/zh/' in texi_file ) process_texi (texi_file, intro_blurb, node_blurb, make_skeleton, os.path.basename (texi_file), node_list, @@ -184,7 +195,7 @@ if make_gettext: 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_name + ' ' + node_list_filename) + os.system ('xgettext --keyword=_doc -c -L Python --no-location -o ' + output_name + ' ' + node_list_filename) else: for texi_file in texi_files: process_texi (texi_file, intro_blurb, node_blurb, make_skeleton,