X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=buildscripts%2Fhtml-gettext.py;h=ccfe6937c0316ec354e2116239475338951a719d;hb=3704bcc57f83c44c279c40fb4b01ee8860144750;hp=02a4c947c0220062f9cbe5a6e8db8b759f67656a;hpb=edf17353d89f4f6bd831466262402bb9151a26ca;p=lilypond.git diff --git a/buildscripts/html-gettext.py b/buildscripts/html-gettext.py index 02a4c947c0..ccfe6937c0 100644 --- a/buildscripts/html-gettext.py +++ b/buildscripts/html-gettext.py @@ -27,71 +27,99 @@ double_punct_char_separator = langdefs.LANGDICT[lang].double_punct_char_sep my_gettext = langdefs.translation[lang] html_codes = ((' -- ', ' – '), - (' --- ', ' — ')) -html2texi = {'command': (re.compile (r'(.*?)'), r'@command{\1}'), - 'code': (re.compile (r'(.*?)'), r'@code{\1}') - } -texi2html = {'command': (re.compile (r'@command{(.*?)}'), r'\1'), - 'code': (re.compile (r'@code{(.*?)}'), r'\1') - } + (' --- ', ' — '), + ("'", '’')) +texi_html_conversion = { + 'command': { + 'html2texi': + (re.compile (r'(?:|)(.*?)(?:|)'), + r'@command{\1}'), + 'texi2html': + (re.compile (r'@command{(.*?)}'), + r'\1'), + }, + 'code': { + 'html2texi': + (re.compile (r'(.*?)'), + r'@code{\1}'), + 'texi2html': + (re.compile (r'@code{(.*?)}'), + r'\1'), + }, + } + whitespaces = re.compile (r'\s+') def _ (s): if not s: return '' - s = whitespaces.sub (' ', s) + str = whitespaces.sub (' ', s) for c in html_codes: - s = s.replace (c[1], c[0]) - for u in html2texi.values(): - s = u[0].sub (u[1], s) - s = my_gettext (s) - for u in texi2html.values(): - s = u[0].sub (u[1], s) + str = str.replace (c[1], c[0]) + for command in texi_html_conversion: + d = texi_html_conversion[command] + str = d['html2texi'][0].sub (d['html2texi'][1], str) + str = my_gettext (str) + str = d['texi2html'][0].sub (d['texi2html'][1], str) for c in html_codes: - s = s.replace (c[0], c[1]) - return s + str = str.replace (c[0], c[1]) + return str + +link_re = re.compile (r'') def link_gettext (m): - return '' + return '' + +makeinfo_title_re = re.compile (r'([^<]*?) - ([^<]*?)') + +def makeinfo_title_gettext (m): + return '' + _ (m.group (1)) + ' - ' + m.group (2) + '' + +texi2html_title_re = re.compile (r'(.+): ([A-Z\d.]+ |)(.+?)') -def title_gettext (m): - return '' + _(m.group(1)) + ' - ' + m.group(2) + '' +def texi2html_title_gettext (m): + return '' + _ (m.group (1)) + double_punct_char_separator + ': ' \ + + m.group (2) + _ (m.group (3)) + '' + +a_href_re = re.compile ('(?s)[^>]*?href="[\\w.#-_]+"[^>]*?>)(?P)?\ +(?PAppendix )?(?P[A-Z0-9.]+ | (?:<){1,2} | [^>:]+?: | |)\ +(?P(?:|||[^>])+?)(?P(?(code)|))\ +(?P (?:>){1,2} | |):?') def a_href_gettext (m): s = '' if m.group(0)[-1] == ':': s = double_punct_char_separator + ':' t = '' - if m.lastindex == 7: - t = m.group(7) - return '' + s + if m.group ('appendix'): + t = _ (m.group ('appendix')) + return '' + s + +h_re = re.compile (r'\s*(Appendix |)([A-Z\d.]+ |)(.+?)\s*') def h_gettext (m): if m.group (3): - s = _(m.group(3)) + s = _ (m.group (3)) else: s= '' - return '' + s +\ - m.group(4) + _(m.group(5)) + '' - -def crossmanual_ref_gettext (m): - return '' + _(m.group(2)) + '' + return '' + s +\ + m.group (4) + _ (m.group (5)) + '' for filename in files: f = open (filename, 'r') page = f.read () - f.close() - page = re.sub (r'', link_gettext, page) - page = re.sub (r'([^<]*?) - ([^<]*?)', title_gettext, page) - # ugh - page = re.sub (r'(?ms))()?(Appendix )?([A-Z\d.]+ |)(.+?)(?(3)):?', a_href_gettext, page) - page = re.sub (r'\s*(Appendix |)([A-Z\d.]+ |)?([^<]+)\s*', h_gettext, page) - page = re.sub (r'(.+?)', crossmanual_ref_gettext, page) - # this is necessary for entries not translated by a_href_gettext - page = re.sub (r'(.+?)', crossmanual_ref_gettext, page) + f.close () + page = link_re.sub (link_gettext, page) + page = makeinfo_title_re.sub (makeinfo_title_gettext, page) + page = texi2html_title_re.sub (texi2html_title_gettext, page) + page = a_href_re.sub (a_href_gettext, page) + page = h_re.sub (h_gettext, page) for w in ('Next:', 'Previous:', 'Up:'): - page = re.sub (w, _(w), page) + page = page.replace (w, _ (w)) page = langdefs.LANGDICT[lang].html_filter (page) f = open (os.path.join (outdir, filename), 'w') f.write (page)