From 862c788de7bb51d58dda7b4a854da3ffce401570 Mon Sep 17 00:00:00 2001 From: John Mandereau Date: Sun, 9 Nov 2008 12:26:53 +0100 Subject: [PATCH] Docs: add support for context names translation in ly snippets --- buildscripts/texi-langutils.py | 8 ++++++-- scripts/lilypond-book.py | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/buildscripts/texi-langutils.py b/buildscripts/texi-langutils.py index 7486ebee01..37de5cc419 100644 --- a/buildscripts/texi-langutils.py +++ b/buildscripts/texi-langutils.py @@ -61,7 +61,7 @@ texinfo_with_menus_re = re.compile (r"^(\*) +([^:\n]+)::.*?$|^@(include|menu|end 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 ]*(.*)$') +ly_string_re = re.compile (r'^([a-zA-Z]+)[\t ]*=|%+[\t ]*(.*)$|\\(?:new|context)\s+(?:[a-zA-Z]*?(?:Staff(?:Group)?|Voice|FiguredBass|FretBoards|Names|Devnull))\s+=\s+"?([a-zA-Z]+)"?\s+') 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): @@ -83,7 +83,7 @@ def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, topfile, outpu elif lines[i].startswith ('@end lilypond'): in_verb_ly_block = False elif in_verb_ly_block: - for (var, comment) in ly_string_re.findall (lines[i]): + for (var, comment, context_id) in ly_string_re.findall (lines[i]): if var: output_file.write ('# ' + printedfilename + ':' + \ str (i + 1) + ' (variable)\n_(r"' + var + '")\n') @@ -91,6 +91,10 @@ def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, topfile, outpu output_file.write ('# ' + printedfilename + ':' + \ str (i + 1) + ' (comment)\n_(r"' + \ comment.replace ('"', '\\"') + '")\n') + elif context_id: + output_file.write ('# ' + printedfilename + ':' + \ + str (i + 1) + ' (context id)\n_(r"' + \ + context_id + '")\n') # process Texinfo node names and section titles if write_skeleton: diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index be9fef694a..b8c765d3fb 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -840,6 +840,8 @@ def verbatim_html (s): ly_var_def_re = re.compile (r'^([a-zA-Z]+)[\t ]*=', re.M) ly_comment_re = re.compile (r'(%+[\t ]*)(.*)$', re.M) +ly_context_id_re = re.compile ('\\\\(?:new|context)\\s+(?:[a-zA-Z]*?(?:Staff\ +(?:Group)?|Voice|FiguredBass|FretBoards|Names|Devnull))\\s+=\\s+"?([a-zA-Z]+)"?\\s+') def ly_comment_gettext (t, m): return m.group (1) + t (m.group (2)) @@ -858,6 +860,10 @@ def verb_ly_gettext (s): s = re.sub (r"(?m)(^|[' \\#])%s([^a-zA-Z])" % v, "\\1" + t (v) + "\\2", s) + for id in ly_context_id_re.findall (s): + s = re.sub (r'(\s+|")%s(\s+|")' % id, + "\\1" + t (id) + "\\2", + s) return s texinfo_lang_re = re.compile ('(?m)^@documentlanguage (.*?)( |$)') -- 2.39.5