4 # Usage: html-gettext.py [-o OUTDIR] LOCALEDIR LANG FILES
6 # -o OUTDIR specifies that output files should be written in OUTDIR
7 # rather than be overwritten
10 # LOCALEDIR should contain 'lilypond-doc' message catalogs
14 # Currently, typo_rules[LANG] only defines the HTML-coded space occuring
15 # before double punctuation characters (i.e. : ; ? ! ) for LANG
17 typo_rules = { 'fr':' ', 'default':'' }
29 optlist, args = getopt.getopt(sys.argv[1:],'o:')
36 if args[1] in typo_rules.keys():
37 dbl_punct_char_separator = typo_rules[args[1]]
39 dbl_punct_char_separator = typo_rules['default']
41 t = gettext.translation('lilypond-doc', args[0], [args[1]])
45 return '<link rel="' + m.group(1) + '" ' + m.group(2) + ' title="' + _(m.group(3)) + '">'
47 def title_gettext (m):
48 return '<title>' + _(m.group(1)) + ' - ' + m.group(2) + '</title>'
50 def a_href_gettext (m):
52 s = dbl_punct_char_separator + ':'
53 elif m.group(4) == None:
55 return '<a ' + (m.group(1) or '') + m.group(2) + _(m.group(3)) + '</a>' + s
58 return '<h' + m.group(1) + ' class="' + m.group(2) + '">' + \
59 (m.group(3) or '') + _(m.group(4)) + '</h' + m.group(1) + '>'
61 for filename in args[2:]:
62 f = open (filename, 'r')
65 page = re.sub (r'<link rel="(up|prev|next)" (.*?) title="([^"]*?)">', link_gettext, page)
66 page = re.sub (r'<title>([^<]*?) - ([^<]*?)</title>', title_gettext, page)
67 page = re.sub (r'<a ((?:rel="\w+")? ?(?:accesskey="[^"]+?" ?)?)(href="[^"]+?">)([^<]+)</a>(:)?', a_href_gettext, page)
68 page = re.sub (r'<h(\d) class="(\w+)">([\d.]+ )?([^<]+)</h\1>', h_gettext, page)
69 for w in ('Next:', 'Previous:', 'Up:'):
70 page = re.sub (w, _(w), page)
71 f = open (os.path.join (outdir, filename), 'w')