From 531b723b9b8d70c56f608c56a8bcf54e7621582c Mon Sep 17 00:00:00 2001 From: John Mandereau Date: Sat, 23 Dec 2006 23:00:17 +0100 Subject: [PATCH] Improve documentation i18n - Documentation/GNUmakefile: get enabled translations from buildscripts/langdefs.py - Documentation/po/GNUmakefile: use $(buildscript-dir) - buildscripts/html-gettext.py: use langdefs.py module and fix regular expressions. - buildscripts/texi-langutils.py: add 'Footnotes' to translatable strings. - make/doclang-targets.make: use new html-gettext argument list --- Documentation/GNUmakefile | 7 ++-- Documentation/po/GNUmakefile | 2 +- buildscripts/html-gettext.py | 60 +++++++++++++++++----------------- buildscripts/texi-langutils.py | 2 +- make/doclang-targets.make | 2 +- 5 files changed, 37 insertions(+), 36 deletions(-) diff --git a/Documentation/GNUmakefile b/Documentation/GNUmakefile index 55f0809885..37a452a11f 100644 --- a/Documentation/GNUmakefile +++ b/Documentation/GNUmakefile @@ -1,7 +1,7 @@ depth = .. NAME = documentation -LANGS = fr # don't enable unpolished or broken translations +LANGS = $(shell $(PYTHON) $(buildscript-dir)/langdefs.py) SUBDIRS=user bibliography pictures topdocs misc po $(LANGS) STEPMAKE_TEMPLATES=documentation texinfo tex LOCALSTEPMAKE_TEMPLATES=lilypond ly @@ -39,8 +39,9 @@ new-lang: cp fr/GNUmakefile $(ISOLANG) cp fr/user/GNUmakefile $(ISOLANG)/user sed -i -e 's/ISOLANG *= *fr/ISOLANG = $(ISOLANG)/' $(ISOLANG)/GNUmakefile $(ISOLANG)/user/GNUmakefile - $(PYTHON) $(depth)/buildscripts/texi-langutils.py -d $(outdir) -b "UNTRANSLATED NODE: IGNORE ME" -o doc.pot --skeleton --gettext ../user/lilypond.tely + $(PYTHON) $(buildscript-dir)/texi-langutils.py -d $(outdir) -b "UNTRANSLATED NODE: IGNORE ME" -o doc.pot --skeleton --gettext ../user/lilypond.tely mv $(outdir)/*.*tely $(ISOLANG)/user msgmerge -U po/lilypond-doc.pot $(outdir)/doc.pot cp po/lilypond-doc.pot po/$(ISOLANG).po -endif \ No newline at end of file + @echo "*** Please add a language definition for $(ISOLANG) in buildscripts/langdefs.py ***" +endif diff --git a/Documentation/po/GNUmakefile b/Documentation/po/GNUmakefile index 23939296d0..925cb7e5a1 100644 --- a/Documentation/po/GNUmakefile +++ b/Documentation/po/GNUmakefile @@ -14,7 +14,7 @@ messages: $(MO_FILES) done po-update: - $(PYTHON) $(depth)/buildscripts/texi-langutils.py -d $(outdir) -o doc.pot --gettext ../$(depth)/Documentation/user/lilypond.tely + $(PYTHON) $(buildscript-dir)/texi-langutils.py -d $(outdir) -o doc.pot --gettext ../$(depth)/Documentation/user/lilypond.tely msgmerge -U lilypond-doc.pot $(outdir)/doc.pot for i in $(CATALOGS); do \ msgmerge -U $$i.po lilypond-doc.pot; \ diff --git a/buildscripts/html-gettext.py b/buildscripts/html-gettext.py index 97f8e5f6f6..3f401382ae 100644 --- a/buildscripts/html-gettext.py +++ b/buildscripts/html-gettext.py @@ -1,45 +1,45 @@ #!@PYTHON@ # html-gettext.py -# Usage: html-gettext.py [-o OUTDIR] LOCALEDIR LANG FILES +# USAGE: html-gettext.py [-o OUTDIR] BUILDSCRIPT-DIR LOCALEDIR LANG FILES # # -o OUTDIR specifies that output files should be written in OUTDIR # rather than be overwritten # -# LANG -# LOCALEDIR should contain 'lilypond-doc' message catalogs - - -### DATA -# Currently, typo_rules[LANG] only defines the HTML-coded space occuring -# before double punctuation characters (i.e. : ; ? ! ) for LANG - -typo_rules = { 'fr':' ', 'default':'' } - - -### PROGRAM import sys import re import os -import string -import gettext import getopt +import gettext optlist, args = getopt.getopt(sys.argv[1:],'o:') +buildscript_dir, localedir, lang = args[0:3] outdir = '.' for x in optlist: if x[0] == '-o': outdir = x[1] -if args[1] in typo_rules.keys(): - dbl_punct_char_separator = typo_rules[args[1]] -else: - dbl_punct_char_separator = typo_rules['default'] +sys.path.append (buildscript_dir) +import langdefs + +double_punct_char_separator = langdefs.LANGDICT[lang].double_punct_char_sep +print localedir +print lang +t = gettext.translation('lilypond-doc', localedir, [lang]) +my_gettext = t.gettext + +html_codes = ((' -- ', ' – '), + (' --- ', ' — ')) -t = gettext.translation('lilypond-doc', args[0], [args[1]]) -_ = t.gettext +def _ (s): + for c in html_codes: + s = s.replace (c[1], c[0]) + s = my_gettext (s) + for c in html_codes: + s = s.replace (c[0], c[1]) + return s def link_gettext (m): return '' @@ -48,24 +48,24 @@ def title_gettext (m): return '' + _(m.group(1)) + ' - ' + m.group(2) + '' def a_href_gettext (m): - if m.group(4) == ':': - s = dbl_punct_char_separator + ':' - elif m.group(4) == None: + if m.group(6) == ':': + s = double_punct_char_separator + ':' + elif m.group(6) == None: s = '' - return '' + s + return '' + s def h_gettext (m): - return '' + \ - (m.group(3) or '') + _(m.group(4)) + '' + return '' + \ + m.group(3) + _(m.group(4)) + '' -for filename in args[2:]: +for filename in args[3:]: f = open (filename, 'r') page = f.read () f.close() page = re.sub (r'', link_gettext, page) page = re.sub (r'([^<]*?) - ([^<]*?)', title_gettext, page) - page = re.sub (r')([^<]+)(:)?', a_href_gettext, page) - page = re.sub (r'([\d.]+ )?([^<]+)', h_gettext, page) + page = re.sub (r')((?:|)(?:[\d.]+ |))([^<]+)(|)(:)?', a_href_gettext, page) + page = re.sub (r'([\d.]+ |)?([^<]+)', h_gettext, page) for w in ('Next:', 'Previous:', 'Up:'): page = re.sub (w, _(w), page) f = open (os.path.join (outdir, filename), 'w') diff --git a/buildscripts/texi-langutils.py b/buildscripts/texi-langutils.py index 09737639b7..62c87619dd 100644 --- a/buildscripts/texi-langutils.py +++ b/buildscripts/texi-langutils.py @@ -86,7 +86,7 @@ if make_gettext: node_list = open (node_list_filename, 'w') for texi_file in texi_files: process_texi (texi_file, intro_blurb, node_blurb, make_skeleton, node_list) - for word in ('Up:', 'Next:', 'Previous:', 'Appendix'): + for word in ('Up:', 'Next:', 'Previous:', 'Appendix', 'Footnotes'): node_list.write ('_("' + word + '")\n') node_list.close () os.system ('xgettext -L Python --no-location -o ' + output_file + ' ' + node_list_filename) diff --git a/make/doclang-targets.make b/make/doclang-targets.make index 7547e39ea6..676cbe43e0 100644 --- a/make/doclang-targets.make +++ b/make/doclang-targets.make @@ -15,7 +15,7 @@ MAKEINFO = LANG=$(ISOLANG) $(MAKEINFO_PROGRAM) --force $(outdir)/lilypond/index.html: $(outdir)/lilypond.nexi 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) $(top-src-dir)/buildscripts/html-gettext.py $(depth)/Documentation/po/$(outdir) $(ISOLANG) + find $(outdir) -name '*.html' | xargs grep -L 'UNTRANSLATED NODE: IGNORE ME' | xargs $(PYTHON) $(buildscript-dir)/html-gettext.py $(buildscript-dir) $(top-src-dir)/Documentation/po/$(outdir) $(ISOLANG) $(outdir)/lilypond.html: $(outdir)/lilypond.nexi -$(MAKEINFO) -I$(outdir) --output=$@ --css-include=$(top-src-dir)/Documentation/texinfo.css --html --no-split --no-headers $< -- 2.39.5