4 # USAGE: html-gettext.py [-o OUTDIR] LANG FILES
6 # -o OUTDIR specifies that output files should be written in OUTDIR
7 # rather than be overwritten
17 optlist, args = getopt.getopt(sys.argv[1:],'o:')
26 double_punct_char_separator = langdefs.LANGDICT[lang].double_punct_char_sep
27 my_gettext = langdefs.translation[lang]
29 html_codes = ((' -- ', ' – '),
30 (' --- ', ' — '),
32 html2texi = {'command':
33 (re.compile (r'<samp><span class="command">(.*?)</span></samp>'),
36 (re.compile (r'<code>(.*?)</code>'),
39 texi2html = {'command':
40 (re.compile (r'@command{(.*?)}'),
41 r'<samp><span class="command">\1</span></samp>'),
43 (re.compile (r'@code{(.*?)}'),
46 whitespaces = re.compile (r'\s+')
52 s = whitespaces.sub (' ', s)
54 s = s.replace (c[1], c[0])
55 for u in html2texi.values():
56 s = u[0].sub (u[1], s)
58 for u in texi2html.values():
59 s = u[0].sub (u[1], s)
61 s = s.replace (c[0], c[1])
64 link_re = re.compile (r'<link rel="(up|prev|next)" (.*?) title="([^"]*?)">')
67 return '<link rel="' + m.group (1) + '" ' + m.group (2) \
68 + ' title="' + _ (m.group (3)) + '">'
70 makeinfo_title_re = re.compile (r'<title>([^<]*?) - ([^<]*?)</title>')
72 def makeinfo_title_gettext (m):
73 return '<title>' + _ (m.group (1)) + ' - ' + m.group (2) + '</title>'
75 texi2html_title_re = re.compile (r'<title>(.+?): ([A-Z\d.]+ |)(.+?)</title>')
77 def texi2html_title_gettext (m):
78 return '<title>' + _ (m.group (1)) + double_punct_char_separator + ': ' \
79 + m.group (2) + _ (m.group (3)) + '</title>'
81 a_href_re = re.compile ('(?s)<a ([^>]*?href="[\\w.#-_]+"[^>]*>(?:<code>|))\
82 (Appendix |)([A-Z0-9.]+ | (?:<){1,2} | [^:<]+?: | |)\
83 (.+?)(</code>| (?:>){1,2} | |)</a>:?')
85 def a_href_gettext (m):
87 if m.group(0)[-1] == ':':
88 s = double_punct_char_separator + ':'
92 return '<a ' + m.group (1) + t + m.group (3) + _ (m.group (4)) + \
93 m.group (5) + '</a>' + s
95 h_re = re.compile (r'<h(\d)( class="\w+"|)>\s*(Appendix |)([A-Z\d.]+ |)?([^<]+)\s*</h\1>')
102 return '<h' + m.group (1) + m.group (2) + '>' + s +\
103 m.group (4) + _ (m.group (5)) + '</h' + m.group (1) + '>'
105 for filename in files:
106 f = open (filename, 'r')
109 page = link_re.sub (link_gettext, page)
110 page = makeinfo_title_re.sub (makeinfo_title_gettext, page)
111 page = texi2html_title_re.sub (texi2html_title_gettext, page)
112 page = a_href_re.sub (a_href_gettext, page)
113 page = h_re.sub (h_gettext, page)
114 for w in ('Next:', 'Previous:', 'Up:'):
115 page = page.replace (w, _ (w))
116 page = langdefs.LANGDICT[lang].html_filter (page)
117 f = open (os.path.join (outdir, filename), 'w')