]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/lilypond-book.py
Add support for LSR snippets texidocs translation
[lilypond.git] / scripts / lilypond-book.py
index dee8223de6e66d51cdd85f2b6268f963cc2ddba4..d4af98cf65f975e616e2cb0aec988b56e9a4adc5 100644 (file)
@@ -197,6 +197,7 @@ default_ly_options = { 'alt': "[image of music]" }
 #
 # Is this pythonic?  Personally, I find this rather #define-nesque. --hwn
 #
+ADDVERSION = 'addversion'
 AFTER = 'after'
 BEFORE = 'before'
 DOCBOOK = 'docbook'
@@ -205,6 +206,7 @@ FILTER = 'filter'
 FRAGMENT = 'fragment'
 HTML = 'html'
 INDENT = 'indent'
+LANG = 'lang'
 LATEX = 'latex'
 LAYOUT = 'layout'
 LINE_WIDTH = 'line-width'
@@ -511,10 +513,12 @@ simple_options = [
     NOINDENT,
     PRINTFILENAME,
     TEXIDOC,
+    LANG,
     VERBATIM,
     FONTLOAD,
     FILENAME,
-    ALT
+    ALT,
+    ADDVERSION
 ]
 
 ly_options = {
@@ -588,7 +592,7 @@ output = {
  <a href="%(base)s.ly">''',
 
         OUTPUT: r'''
-  <img align="center" valign="center"
+  <img align="middle" 
     border="0" src="%(image)s" alt="%(alt)s">''',
 
         PRINTFILENAME: '<p><tt><a href="%(base)s.ly">%(filename)s</a></tt></p>',
@@ -653,7 +657,7 @@ output = {
 @html
 <p>
  <a href="%(base)s.ly">
-  <img align="center" valign="center"
+  <img align="middle"
     border="0" src="%(image)s" alt="%(alt)s">
  </a>
 </p>
@@ -679,9 +683,14 @@ output = {
 ''',
 
         VERBATIM: r'''@exampleindent 0
-@verbatim
+%(version)s@verbatim
 %(verb)s@end verbatim
 ''',
+
+        ADDVERSION: r'''@example
+\version @w{"@version{}"}
+@end example
+'''
     },
 }
 
@@ -807,6 +816,8 @@ def split_options (option_string):
                     option_string)
     return []
 
+texinfo_lang_re = re.compile ('(?m)^@documentlanguage (.*?)( |$)')
+
 def set_default_options (source):
     global default_ly_options
     if not default_ly_options.has_key (LINE_WIDTH):
@@ -815,6 +826,11 @@ def set_default_options (source):
             default_ly_options[LINE_WIDTH] = \
              '''%.0f\\pt''' % textwidth
         elif global_options.format == TEXINFO:
+            m = texinfo_lang_re.search (source)
+            if m and not m.group (1).startswith ('en'):
+                default_ly_options[LANG] = m.group (1)
+            else:
+                default_ly_options[LANG] = ''
             for (k, v) in texinfo_line_widths.items ():
                 # FIXME: @layout is usually not in
                 # chunk #0:
@@ -1244,32 +1260,29 @@ class Lilypond_snippet (Snippet):
         str = ''
         if PRINTFILENAME in self.option_dict:
             base = self.basename ()
-            filename = self.substring ('filename')
-            str = output[global_options.format][PRINTFILENAME] % vars ()
+            filename = os.path.basename (self.substring ('filename'))
+            str = output[format][PRINTFILENAME] % vars ()
 
         return str
 
     def output_texinfo (self):
-        str = ''
-        if self.output_print_filename (TEXINFO):
-            str += ('@html\n'
-                + self.output_print_filename (HTML)
-                + '\n@end html\n')
-            str += ('@tex\n'
-                + self.output_print_filename (LATEX)
-                + '\n@end tex\n')
+        str = self.output_print_filename (TEXINFO)
         base = self.basename ()
         if TEXIDOC in self.option_dict:
             texidoc = base + '.texidoc'
-            if os.path.exists (texidoc):
+            translated_texidoc = texidoc + default_ly_options[LANG]
+            if os.path.exists (translated_texidoc):
+                str += '@include %(translated_texidoc)s\n\n' % vars ()
+            elif os.path.exists (texidoc):
                 str += '@include %(texidoc)s\n\n' % vars ()
 
         substr = ''
         if VERBATIM in self.option_dict:
+            version = ''
+            if ADDVERSION in self.option_dict:
+                version = output[TEXINFO][ADDVERSION]
             verb = self.verb_ly ()
-            substr += output[TEXINFO][VERBATIM] % vars ()
-            if not QUOTE in self.option_dict:
-                substr = output[TEXINFO][NOQUOTE] % {'str':substr}
+            substr = output[TEXINFO][VERBATIM] % vars ()
         substr += self.output_info ()
         if LILYQUOTE in self.option_dict:
             substr = output[TEXINFO][QUOTE] % {'str':substr}
@@ -1643,10 +1656,8 @@ def write_if_updated (file_name, lines):
             progress ('\n')
 
             # this prevents make from always rerunning lilypond-book:
-            # .texi target must be touched in order to be up to date
-            if global_options.format == 'texinfo':
-                os.utime (file_name, None)
-            return
+            # output file must be touched in order to be up to date
+            os.utime (file_name, None)
     except:
         pass
 
@@ -1757,13 +1768,10 @@ def do_file (input_filename):
             progress ('\n')
             return do_file (name)
 
-        include_chunks = map (process_include,
-                   filter (lambda x: is_derived_class (x.__class__,
-                                     Include_snippet),
-                       chunks))
-
+        include_chunks = [process_include (c) for c in chunks
+                          if is_derived_class (c.__class__, Include_snippet)]
 
-        return chunks + reduce (lambda x,y: x + y, include_chunks, [])
+        return chunks + reduce (operator.add, include_chunks, [])
         
     except Compile_error:
         os.chdir (original_dir)