From: Jan Nieuwenhuizen Date: Mon, 31 Jan 2005 15:43:39 +0000 (+0000) Subject: * scripts/lilypond-book.py: Resurrect HTML links to .ly source. X-Git-Tag: release/2.5.14~183 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=fce4a902f04e3e2fef1f6f70f2f4e8e19f09b2d8;p=lilypond.git * scripts/lilypond-book.py: Resurrect HTML links to .ly source. Bugfix: @include .tex (not .texi). Small cleanups. * stepmake/bin/add-html-footer.py (i18n): New function. --- diff --git a/ChangeLog b/ChangeLog index 9c8a76b158..cfcacab43d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-01-31 Jan Nieuwenhuizen + + * scripts/lilypond-book.py: Resurrect HTML links to .ly source. + Bugfix: @include .tex (not .texi). Small cleanups. + + * stepmake/bin/add-html-footer.py (i18n): New function. + 2005-01-31 Werner Lemberg * mf/feta-nummer.mf: Removed. Unused. diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 7add63df5c..96a8113e51 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -489,14 +489,22 @@ output = { OUTPUT: r''' @iftex -@include %(base)s-systems.texi +@include %(base)s-systems.tex @end iftex ''', OUTPUTIMAGE: r'''@noindent -@ifnottex +@ifinfo @image{%(base)s,,,[image of music],%(ext)s} -@end ifnottex +@end ifinfo +@html +

+ + [image of music] + +

+@end html ''', PRINTFILENAME: '''@file{%(filename)s} @@ -878,7 +886,7 @@ class Lilypond_snippet (Snippet): def texstr_is_outdated (self): if backend == 'ps': return 0 - + base = self.basename () ok = self.ly_is_outdated () ok = ok and (os.path.exists (base + '.texstr')) @@ -939,8 +947,8 @@ class Lilypond_snippet (Snippet): ext = '' str += output[TEXINFO][OUTPUTIMAGE] % vars () - base = self.basename() - str += output[format][OUTPUT] % vars() + base = self.basename () + str += output[format][OUTPUT] % vars () return str def output_latex (self): @@ -985,10 +993,10 @@ class Lilypond_snippet (Snippet): verb = verbatim_texinfo (self.substring ('code')) str += (output[TEXINFO][VERBATIM] % vars ()) if not QUOTE in self.options: - str = output[TEXINFO][NOQUOTE] % vars() + str = output[TEXINFO][NOQUOTE] % vars () str += self.output_info () - + # str += ('@ifinfo\n' + self.output_info () + '\n@end ifinfo\n') # str += ('@tex\n' + self.output_latex () + '\n@end tex\n') # str += ('@html\n' + self.output_html () + '\n@end html\n') @@ -1247,7 +1255,7 @@ def guess_format (input_filename): % input_filename)) ly.exit (1) return format - + def do_file (input_filename): # Ugh. if not input_filename or input_filename == '-': @@ -1429,7 +1437,7 @@ def main (): global process_cmd, format format = guess_format (files[0]) - formats = "ps" + formats = 'ps' if format == TEXINFO: formats += ',png' if process_cmd == '': diff --git a/stepmake/bin/add-html-footer.py b/stepmake/bin/add-html-footer.py index 6d0d756c0a..ec7cac2ab9 100644 --- a/stepmake/bin/add-html-footer.py +++ b/stepmake/bin/add-html-footer.py @@ -235,6 +235,7 @@ def do_file (f): else: s = s + footer + s = i18n (f, s) #URUGRGOUSNGUOUNRIU index = index_url @@ -263,10 +264,8 @@ def do_file (f): subst = globals () subst.update (locals()) - - s = s % subst - + # urg # maybe find first node? fallback_web_title = '-- --' @@ -283,6 +282,77 @@ def do_file (f): open (f, 'w').write (s) + +localedir = 'out/locale' +try: + import gettext + gettext.bindtextdomain ('newweb', localedir) + gettext.textdomain ('newweb') + _ = gettext.gettext +except: + def _ (s): + return s +underscore = _ + + +LANGUAGES = ( + ('site', 'English'), + ('nl', 'Nederlands'), + ) + +language_available = _ ("Other languages: %s.") % "%(language_menu)s" +browser_language = _ ("Using automatic language selection.") \ + % "%(root_url)sabout/browser-language" + +LANGUAGES_TEMPLATE = '''\ +

+ %(language_available)s +
+ %(browser_language)s +

+''' % vars () + +def file_lang (file, lang): + (base, ext) = os.path.splitext (file) + base = os.path.splitext (base)[0] + if lang and lang != 'site': + return base + '.' + lang + ext + return base + ext + + +def i18n (file_name, page): + # ugh + root_url = "/web/" + + base_name = os.path.basename (file_name) + + lang = '' + m = re.match ('.*[.]([^.]*).html', file_name) + if m: + lang = m.group (1) + + # Find available translations of this page. + available = filter (lambda x: lang != x[0] \ + and os.path.exists (file_lang (file_name, x[0])), + LANGUAGES) + + # Strip .html, .png suffix for auto language selection. + page = re.sub ('''(href|src)=[\'"]([^/][.]*[^.:\'"]*)(.html(#[^"]*)|.png)[\'"]''', + '\\1="\\2"', page) + + # Create language menu. + language_menu = '' + for (prefix, name) in available: + lang_file = file_lang (base_name, prefix) + language_menu += '%(name)s' % vars () + + languages = '' + if language_menu: + languages = LANGUAGES_TEMPLATE % vars () + + return page + languages + ## end i18n + for f in files: do_file (f)