]> git.donarmstrong.com Git - lilypond.git/blobdiff - buildscripts/html-gettext.py
Merge branch 'master' of /home/lilycvs/git/lily/
[lilypond.git] / buildscripts / html-gettext.py
index d6a06c901c83deed52849c34a52db9ae8cea1087..a63fc3c3592649524533dc9c77af0a0ba46c145c 100644 (file)
@@ -1,7 +1,7 @@
 #!@PYTHON@
 # html-gettext.py
 
-# USAGE:  html-gettext.py [-o OUTDIR] BUILDSCRIPT-DIR LOCALEDIR LANG FILES
+# USAGE:  html-gettext.py [-o OUTDIR] LANG FILES
 #
 # -o OUTDIR specifies that output files should be written in OUTDIR
 #    rather than be overwritten
@@ -11,24 +11,20 @@ import sys
 import re
 import os
 import getopt
-import gettext
+
+import langdefs
 
 optlist, args = getopt.getopt(sys.argv[1:],'o:')
-buildscript_dir, localedir, lang = args[0:3]
+lang = args[0]
+files = args [1:]
 
 outdir = '.'
 for x in optlist:
        if x[0] == '-o':
                outdir = x[1]
 
-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
+my_gettext = langdefs.translation[lang]
 
 html_codes = ((' -- ', ' – '),
              (' --- ', ' — '))
@@ -38,10 +34,13 @@ html2texi = {'command': (re.compile (r'<samp><span class="command">(.*?)</span><
 texi2html = {'command': (re.compile (r'@command{(.*?)}'), r'<samp><span class="command">\1</span></samp>'),
             'code': (re.compile (r'@code{(.*?)}'), r'<code>\1</code>')
             }
+whitespaces = re.compile (r'\s+')
+
 
 def _ (s):
        if not s:
                return ''
+       s = whitespaces.sub (' ', s)
        for c in html_codes:
                s = s.replace (c[1], c[0])
        for u in html2texi.values():
@@ -69,24 +68,31 @@ def a_href_gettext (m):
        return '<a ' + (m.group(1) or '') + m.group(2) + (m.group(3) or '') + _(m.group(4)) + m.group(5) + _(m.group(6)) + t + '</a>' + s
 
 def h_gettext (m):
-       return '<h' + m.group(1) + m.group(2) + '>' + \
-              m.group(3) + _(m.group(4)) + '</h' + m.group(1) + '>'
+       if m.group (3):
+               s = _(m.group(3))
+       else:
+               s= ''
+       return '<h' + m.group(1) + m.group(2) + '>' + s +\
+              m.group(4) + _(m.group(5)) + '</h' + m.group(1) + '>'
 
-def rglos_gettext (m):
-       return '<a href="../music-glossary/' + m.group(1) + '">' + _(m.group(2)) + '</a>'
+def crossmanual_ref_gettext (m):
+       return '<a href="' + m.group(1) + '">' + _(m.group(2)) + '</a>'
 
-for filename in args[3:]:
+for filename in files:
        f = open (filename, 'r')
        page = f.read ()
        f.close()
        page = re.sub (r'<link rel="(up|prev|next)" (.*?) title="([^"]*?)">', link_gettext, page)
        page = re.sub (r'<title>([^<]*?) - ([^<]*?)</title>', title_gettext, page)
        # ugh
-       page = re.sub (r'<a ((?:rel="\w+")? ?(?:accesskey="[^"]+?")? ?(?:name=".*?")? ?)(href="[^"]+?">)(<code>)?(Appendix )?([A-Z\d.]+ |)(.+?)(?(3)</code>)</a>:?', a_href_gettext, page)
-       page = re.sub (r'<h(\d)( class="\w+"|)>([\d.]+ |)?([^<]+)</h\1>', h_gettext, page)
-       page = re.sub (r'<a href="../music-glossary/(.+?)">(.+?)</a>', rglos_gettext, page)
+       page = re.sub (r'(?ms)<a ((?:rel="\w+")? ?(?:accesskey="[^"]+?")? ?(?:name=".*?")? ?)(href=".+?">)(<code>)?(Appendix )?([A-Z\d.]+ |)(.+?)(?(3)</code>)</a>:?', a_href_gettext, page)
+       page = re.sub (r'<h(\d)( class="\w+"|)>(Appendix |)([A-Z\d.]+ |)?([^<]+)</h\1>', h_gettext, page)
+       page = re.sub (r'<a href="(\.\./(?:music-glossary|lilypond-program/)?(?:.+?))">(.+?)</a>', crossmanual_ref_gettext, page)
+       # this is necessary for entries not translated by a_href_gettext
+       page = re.sub (r'<a href="(.+?)">(.+?)</a>', crossmanual_ref_gettext, page)
        for w in ('Next:', 'Previous:', 'Up:'):
                page = re.sub (w, _(w), page)
+       page = langdefs.LANGDICT[lang].html_filter (page)
        f = open (os.path.join (outdir, filename), 'w')
        f.write (page)
        f.close ()