4 # USAGE: html-gettext.py [-o OUTDIR] BUILDSCRIPT-DIR LOCALEDIR LANG FILES
6 # -o OUTDIR specifies that output files should be written in OUTDIR
7 # rather than be overwritten
16 optlist, args = getopt.getopt(sys.argv[1:],'o:')
17 buildscript_dir, localedir, lang = args[0:3]
24 sys.path.append (buildscript_dir)
27 double_punct_char_separator = langdefs.LANGDICT[lang].double_punct_char_sep
30 t = gettext.translation('lilypond-doc', localedir, [lang])
31 my_gettext = t.gettext
33 html_codes = ((' -- ', ' – '),
34 (' --- ', ' — '))
35 html2texi_command = re.compile (r'<samp><span class="command">(.*?)</span></samp>')
36 texi2html_command = re.compile (r'@command{(.*?)}')
40 s = s.replace (c[1], c[0])
41 s = html2texi_command.sub (r'@command{\1}', s)
43 s = texi2html_command.sub (r'<samp><span class="command">\1</span></samp>', s)
45 s = s.replace (c[0], c[1])
49 return '<link rel="' + m.group(1) + '" ' + m.group(2) + ' title="' + _(m.group(3)) + '">'
51 def title_gettext (m):
52 return '<title>' + _(m.group(1)) + ' - ' + m.group(2) + '</title>'
54 def a_href_gettext (m):
56 s = double_punct_char_separator + ':'
57 elif m.group(6) == None:
59 return '<a ' + (m.group(1) or '') + m.group(2) + m.group(3) + _(m.group(4)) + m.group(5) + '</a>' + s
62 return '<h' + m.group(1) + m.group(2) + '>' + \
63 m.group(3) + _(m.group(4)) + '</h' + m.group(1) + '>'
65 def rglos_gettext (m):
66 return '<a href="../music-glossary/' + m.group(1) + '">' + _(m.group(2)) + '</a>'
68 for filename in args[3:]:
69 f = open (filename, 'r')
72 page = re.sub (r'<link rel="(up|prev|next)" (.*?) title="([^"]*?)">', link_gettext, page)
73 page = re.sub (r'<title>([^<]*?) - ([^<]*?)</title>', title_gettext, page)
74 page = re.sub (r'<a ((?:rel="\w+")? ?(?:accesskey="[^"]+?")? ?(?:name=".*?")? ?)(href="[^"]+?">)((?:<code>|)(?:[\d.]+ |))([^<]+)(</code>|)</a>(:)?', a_href_gettext, page)
75 page = re.sub (r'<h(\d)( class="\w+"|)>([\d.]+ |)?([^<]+)</h\1>', h_gettext, page)
76 page = re.sub (r'<a href="../music-glossary/(.+?)">(.+?)</a>', rglos_gettext, page)
77 for w in ('Next:', 'Previous:', 'Up:'):
78 page = re.sub (w, _(w), page)
79 f = open (os.path.join (outdir, filename), 'w')