From e89d4b8578439d07a63dc2029c6d8fe016051fe3 Mon Sep 17 00:00:00 2001 From: John Mandereau Date: Mon, 25 Jun 2007 22:28:10 +0200 Subject: [PATCH] Fix translated docs makefile and scripts * buildscripts/texi-gettext.py: gettext @ref's properly by eating trailing spaces and newlines. * buildscripts/texi-gettext.py, make/doclang-targets.make: write gettexted *.texi to *.pdftexi to avoid makeinfo generate unwanted filenames. * make/doclang-targets.make(local-WWW): use mass-link.py for merging output. --- buildscripts/mass-link.py | 28 +++++++++++++++++++++++----- buildscripts/texi-gettext.py | 36 +++++++++++++++++++++++++----------- make/doclang-targets.make | 14 ++++++++------ 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/buildscripts/mass-link.py b/buildscripts/mass-link.py index 1f0ff074c6..61ea81e2db 100644 --- a/buildscripts/mass-link.py +++ b/buildscripts/mass-link.py @@ -1,10 +1,11 @@ #!@PYTHON@ # mass-link.py -# USAGE: mass-link.py symbolic | hard SOURCEDIR DESTDIR FILES +# USAGE: mass-link.py [--prepend-suffix SUFFIX] symbolic | hard SOURCEDIR DESTDIR FILES # # create hard or symbolic links to SOURCEDIR/FILES in DESTDIR # +# if --prepend-suffix is specified, link to foo.bar will be called fooSUFFIX.bar # shell-wildcard expansion is performed on FILES. print "mass_link.py" @@ -12,9 +13,26 @@ print "mass_link.py" import sys import os import glob - -link_type, source_dir, dest_dir = sys.argv[1:4] -files = sys.argv[4:] +import getopt + +optlist, args = getopt.getopt (sys.argv[1:], '', ['prepend-suffix=']) +link_type, source_dir, dest_dir = args[0:3] +files = args[3:] + +prepended_suffix = '' +for x in optlist: + if x[0] == '--prepend-suffix': + prepended_suffix = x[1] + +if prepended_suffix: + def insert_suffix (p): + l = p.split ('.') + if len (l) >= 2: + l[-2] += prepended_suffix + return '.'.join (l) + return p + prepended_suffix +else: + insert_suffix = lambda p: p if link_type == 'symbolic': link = os.symlink @@ -28,7 +46,7 @@ sourcefiles = [] for pattern in files: sourcefiles += (glob.glob (os.path.join (source_dir, pattern))) -destfiles = map (lambda f: os.path.join (dest_dir, os.path.basename (f)), sourcefiles) +destfiles = map (lambda f: os.path.join (dest_dir, insert_suffix (os.path.basename (f))), sourcefiles) def force_link (src,dest): if os.path.exists (dest): diff --git a/buildscripts/texi-gettext.py b/buildscripts/texi-gettext.py index dcbcded41b..49cc62288b 100644 --- a/buildscripts/texi-gettext.py +++ b/buildscripts/texi-gettext.py @@ -4,8 +4,7 @@ # 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" @@ -16,7 +15,7 @@ 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 = '.' @@ -31,7 +30,11 @@ 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|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'\* (.*?)::') # Why not use recode? # - well, it would add one more dependency... @@ -94,32 +97,43 @@ accents2texi = ( 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'@(node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading)( )(.*?)(\n)', title_gettext, page) - page = re.sub (r'(?L)@(rglos|ref)(\{)(.*?)(\})', title_gettext, page) - page = re.sub (r'\* (.*?)::', menu_entry_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.")) + includes = include_re.findall (page) + page = include_re.sub (lambda m: include_replace (m, filename), page) for (u_char, texiaccent_char) in accents2texi: page = page.replace (u_char, texiaccent_char) - p = os.path.join (outdir, filename) + 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) diff --git a/make/doclang-targets.make b/make/doclang-targets.make index 1b21da230b..30a438692d 100644 --- a/make/doclang-targets.make +++ b/make/doclang-targets.make @@ -14,7 +14,7 @@ $(outdir)/lilypond.nexi: $(ITELY_FILES) $(ITEXI_FILES) MAKEINFO = LANG=$(ISOLANG) $(MAKEINFO_PROGRAM) --force -$(outdir)/lilypond/index.html: $(outdir)/lilypond.nexi user-ln doc-po +$(outdir)/lilypond/index.html: $(outdir)/lilypond.nexi $(outdir)/user-ln doc-po mkdir -p $(dir $@) -$(MAKEINFO) -I$(outdir) --output=$(outdir)/lilypond --css-include=$(top-src-dir)/Documentation/texinfo.css --html $< find $(outdir) -name '*.html' | xargs grep -L 'UNTRANSLATED NODE: IGNORE ME' | xargs $(PYTHON) $(buildscript-dir)/html-gettext.py $(buildscript-dir) $(top-build-dir)/Documentation/po/$(outdir) $(ISOLANG) @@ -24,13 +24,14 @@ $(outdir)/lilypond/index.html: $(outdir)/lilypond.nexi user-ln doc-po #$(outdir)/lilypond.html: $(outdir)/lilypond.nexi # -$(MAKEINFO) -I$(outdir) --output=$@ --css-include=$(top-src-dir)/Documentation/texinfo.css --html --no-split --no-headers $< -$(outdir)/%.pdf: $(outdir)/%.texi user-ln doc-po +$(outdir)/%.pdf: $(outdir)/%.texi $(outdir)/user-ln doc-po $(PYTHON) $(buildscript-dir)/texi-gettext.py $(buildscript-dir) $(top-build-dir)/Documentation/po/$(outdir) $(ISOLANG) $< - cp $< $(<)~ - cd $(outdir); texi2pdf --batch $(TEXINFO_PAPERSIZE_OPTION) $(