X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=buildscripts%2Fhtml-gettext.py;h=3f401382ae23cf3c54c8e867a00fb1f270fc96e4;hb=87eedcd59f4082cb0841528ad5bc82cb1d1191e3;hp=97f8e5f6f66fbc806490d01a12625800cb3f34e9;hpb=9e69cb84d6ee5b0a861cd97869b10e3bdf0c833c;p=lilypond.git 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')