X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=buildscripts%2Ftexi-gettext.py;h=2c993526660c9d7e0eef033237b84da92f20ccf8;hb=ee82b79ea25f8773097b52ee5932ee5f42794c04;hp=7dd751eca413993be0388e612bb79610b0b3eceb;hpb=eb1c49112df603bb1b885249d24870c462d8e1ee;p=lilypond.git diff --git a/buildscripts/texi-gettext.py b/buildscripts/texi-gettext.py index 7dd751eca4..2c99352666 100644 --- a/buildscripts/texi-gettext.py +++ b/buildscripts/texi-gettext.py @@ -1,19 +1,21 @@ #!@PYTHON@ +# -*- coding: utf-8 -*- # texi-gettext.py # USAGE: texi-gettext.py [-o OUTDIR] BUILDSCRIPT-DIR LOCALEDIR LANG FILES # -# -o OUTDIR specifies that output files should be written in OUTDIR -# rather than be overwritten +# -o OUTDIR specifies that output files should rather be written in OUTDIR # +print "texi_gettext.py" + import sys import re import os import getopt import gettext -optlist, args = getopt.getopt(sys.argv[1:],'o:') +optlist, args = getopt.getopt (sys.argv[1:],'o:') buildscript_dir, localedir, lang = args[0:3] outdir = '.' @@ -28,31 +30,50 @@ double_punct_char_separator = langdefs.LANGDICT[lang].double_punct_char_sep t = gettext.translation('lilypond-doc', localedir, [lang]) _doc = t.gettext -include_re = re.compile (r'@include (.*?)$', re.M) +include_re = re.compile (r'@include ((?!lily-).*?)\.texi$', re.M) +whitespaces = re.compile (r'\s+') +ref_re = re.compile (r'(?ms)@(rglos|ruser|rprogram|ref)(\{)(.*?)(\})') +node_section_re = re.compile (r'@(node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading)( )(.*?)(\n)') +menu_entry_re = re.compile (r'\* (.*?)::') def title_gettext (m): - return '@' + m.group (1) + m.group (2) + _doc (m.group (3)) + m.group (4) + if m.group (2) == '{': + r = whitespaces.sub (' ', m.group (3)) + else: + r = m.group (3) + return '@' + m.group (1) + m.group (2) + _doc (r) + m.group (4) + +def menu_entry_gettext (m): + return '* ' + _doc (m.group (1)) + '::' + +def include_replace (m, filename): + if os.path.exists (os.path.join (os.path.dirname (filename), m.group(1)) + '.texi'): + return '@include ' + m.group(1) + '.pdftexi' + return m.group(0) def process_file (filename): print "Processing %s" % filename f = open (filename, 'r') page = f.read () f.close() - page = re.sub (r'(?L)@(rglos|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading)(\{| )(.*?)(\}|\n)', title_gettext, page) + page = node_section_re.sub (title_gettext, page) + page = ref_re.sub (title_gettext, page) + page = menu_entry_re.sub (menu_entry_gettext, page) page = page.replace ("""-- SKELETON FILE -- When you actually translate this file, please remove these lines as well as all `UNTRANSLATED NODE: IGNORE ME' lines.""", '') page = page.replace ('UNTRANSLATED NODE: IGNORE ME', _doc ("This section has not been translated yet; please refer to the manual in English.")) - f = open (os.path.join (outdir, filename), 'w') + includes = include_re.findall (page) + page = include_re.sub (lambda m: include_replace (m, filename), page) + p = os.path.join (outdir, filename) [:-4] + 'pdftexi' + f = open (p, 'w') f.write (page) f.close () dir = os.path.dirname (filename) - for file in include_re.findall (page): - p = os.path.join (dir, file) + for file in includes: + p = os.path.join (dir, file) + '.texi' if os.path.exists (p): process_file (p) for filename in args[3:]: process_file (filename) - -toto = raw_input ("Press enter to continue")