]> git.donarmstrong.com Git - lilypond.git/commitdiff
Improve Python scripts localization
authorJohn Mandereau <john.mandereau@gmail.com>
Wed, 13 Feb 2008 20:48:30 +0000 (21:48 +0100)
committerJohn Mandereau <john.mandereau@gmail.com>
Wed, 13 Feb 2008 20:48:30 +0000 (21:48 +0100)
* all scripts: add --help and --version options manually so they are
localized, and mark 'Bugs' for translation;

* musicxml2ly.py: use gettext from lilylib, uniformize option
descriptions (always start downcase and do not end with a period);

* musicexp.py, musicxml.py: use encoded writing to stderr and save
translation work by creating error and warning functions.

python/lilylib.py
python/musicexp.py
python/musicxml.py
scripts/abc2ly.py
scripts/convert-ly.py
scripts/etf2ly.py
scripts/lilypond-book.py
scripts/midi2ly.py
scripts/musicxml2ly.py

index ec38d70d73471defa16afdb0b2cc1a6b2b4e47b8..cfa5e67d0a7b0de58428f76b3ea96efac1cecdc1 100644 (file)
@@ -59,6 +59,11 @@ underscore = _
 def encoded_write(f, s):
     f.write (s.encode (f.encoding or 'utf_8'))
 
+# ugh, Python 2.5 optparse requires Unicode strings in some argument
+# functions, and refuse them in some other places
+def display_encode (s):
+    return s.encode (sys.stderr.encoding or 'utf_8')
+
 def stderr_write (s):
     encoded_write (sys.stderr, s)
 
index 07af416ab779ef2d024423e98b13baa821fde1d6..b266830d0726bd32e43b884e5ae1e6e2f795836a 100644 (file)
@@ -2,6 +2,9 @@ import inspect
 import sys
 import string
 import re
+import lilylib
+
+_ = lilylib._
 
 from rational import Rational
 
@@ -9,6 +12,10 @@ from rational import Rational
 previous_pitch = None
 relative_pitches = False
 
+def warning (str):
+    ly.stderr_write ((_ ("warning: %s") % str) + "\n")
+
+
 def escape_instrument_string (input_string):
     retstring = string.replace (input_string, "\"", "\\\"")
     if re.match ('.*[\r\n]+.*', retstring):
@@ -567,7 +574,8 @@ class RepeatedMusic:
             self.music = SequentialMusic ()
             self.music.elements = music
         else:
-            sys.stderr.write (_ ("WARNING: Unable to set the music %s for the repeat %s" % (music, self)))
+            warning (_ ("unable to set the music %(music)s for the repeat %(repeat)s" % \
+                            {'music':music, 'repeat':self}))
     def add_ending (self, music):
         self.endings.append (music)
     def print_ly (self, printer):
@@ -575,7 +583,7 @@ class RepeatedMusic:
         if self.music:
             self.music.print_ly (printer)
         else:
-            sys.stderr.write (_ ("WARNING: Encountered repeat without body\n"))
+            warning (_ ("encountered repeat without body"))
             printer.dump ('{}')
         if self.endings:
             printer.dump ('\\alternative {')
index f96895f638e036445eb6ea7c4f18565d0de7ebb1..a6b8c2ab4133c0d09e1299ae0a0c1032c405ce33 100644 (file)
@@ -5,6 +5,13 @@ from rational import *
 import re
 import sys
 import copy
+import lilylib
+
+_ = lilylib._
+
+def error (str):
+    ly.stderr_write ((_ ("error: %s") % str) + "\n")
+
 
 def escape_ly_output_string (input_string):
     return_string = input_string
@@ -262,7 +269,7 @@ class Attributes (Measure_element):
             else:
                 return (4, 4)
         except KeyError:
-            sys.stderr.write (_ ("error: requested time signature, but time sig is unknown\n"))
+            error (_ ("requested time signature, but time sig is unknown"))
             return (4, 4)
 
     # returns clef information in the form ("cleftype", position, octave-shift)
@@ -362,7 +369,7 @@ class Part_list (Music_xml_node):
         if instrument_name:
             return instrument_name
         else:
-            sys.stderr.write (_ ("Unable to find find instrument for ID=%s\n") % id)
+            lilylib.stderr_write (_ ("Unable to find find instrument for ID=%s\n") % id)
             return "Grand Piano"
 
 class Part_group (Music_xml_node):
index 2693817e92c0722d1ffe42a4a5cc5ee802826181..a1fbf38a710e51eebb5de849a7921b1729c0856c 100644 (file)
@@ -1340,17 +1340,25 @@ def print_version ():
 
 def get_option_parser ():
     p = ly.get_option_parser (usage=_ ("%s [OPTION]... FILE") % 'abc2ly',
-                 version="abc2ly (LilyPond) @TOPLEVEL_VERSION@",
                  description=_ ('''abc2ly converts ABC music files (see
-%s) to LilyPond input.''') % 'http://www.gre.ac.uk/~c.walshaw/abc2mtex/abc.txt')
+%s) to LilyPond input.''') % 'http://www.gre.ac.uk/~c.walshaw/abc2mtex/abc.txt',
+                 add_help_option=False)
 
+    p.version = "abc2ly (LilyPond) @TOPLEVEL_VERSION@"
+    p.add_option("--version",
+                 action="version",
+                 help=_ ("show version number and exit"))
+
+    p.add_option("-h", "--help",
+                 action="help",
+                 help=_ ("show this help and exit"))
     p.add_option ('-o', '--output', metavar='FILE',
                   help=_ ("write output to FILE"),
                   action='store')
     p.add_option ('-s', '--strict', help=_ ("be strict about succes"),
                   action='store_true')
     p.add_option ('-b', '--beams', help=_ ("preserve ABC's notion of beams"))
-    p.add_option_group ('bugs',
+    p.add_option_group (ly.display_encode (_ ('Bugs')),
                         description=(_ ('Report bugs via')
                                      + ''' http://post.gmane.org/post.php'''
                                      '''?group=gmane.comp.gnu.lilypond.bugs\n'''))
index 6d7eda4a41dd712884a96e137947ce2c7d91025c..d4e4ceecc284c4a335dbd999ab58b399d2fbdb1e 100644 (file)
@@ -69,8 +69,17 @@ Copyright (c) %s by
 
 def get_option_parser ():
     p = ly.get_option_parser (usage=_ ("%s [OPTION]... FILE") % 'convert-ly',
-                  version="@TOPLEVEL_VERSION@",
-                  description=help_summary)
+                  description=help_summary,
+                  add_help_option=False)
+
+    p.version="@TOPLEVEL_VERSION@"
+    p.add_option("--version",
+                 action="version",
+                 help=_ ("show version number and exit"))
+
+    p.add_option("-h", "--help",
+                 action="help",
+                 help=_ ("show this help and exit"))
 
     p.add_option ('-f', '--from', 
               action="store",
@@ -99,7 +108,7 @@ def get_option_parser ():
               dest="to_version",
               default='')
 
-    p.add_option_group ('bugs',
+    p.add_option_group (ly.display_encode (_ ('Bugs')),
                         description=(_ ("Report bugs via")
                                      + ''' http://post.gmane.org/post.php'''
                                      '''?group=gmane.comp.gnu.lilypond.bugs\n'''))
index dd431d699a22d0991b83fd893cec73a99e5d3f9f..4e2fcc7a11fb4606a03fe24cc41333c82706135b 100644 (file)
@@ -1178,9 +1178,16 @@ Copyright (c) %s by
 
 def get_option_parser ():
     p = ly.get_option_parser (usage=_ ("%s [OPTION]... ETF-FILE") % 'etf2ly',
-                 version="etf2ly (LilyPond) @TOPLEVEL_VERSION@",
                  description=_ ("""Enigma Transport Format is a format used by Coda Music Technology's
-Finale product.  etf2ly converts a subset of ETF to a ready-to-use LilyPond file."""))
+Finale product.  etf2ly converts a subset of ETF to a ready-to-use LilyPond file."""),
+                 add_help_option=False)
+    p.add_option("-h", "--help",
+                 action="help",
+                 help=_ ("show this help and exit"))
+    p.version = "etf2ly (LilyPond) @TOPLEVEL_VERSION@"
+    p.add_option("--version",
+                 action="version",
+                 help=_ ("show version number and exit"))
     p.add_option ('-o', '--output', help=_ ("write output to FILE"),
            metavar=_("FILE"),
            action='store')
@@ -1188,7 +1195,7 @@ Finale product.  etf2ly converts a subset of ETF to a ready-to-use LilyPond file
            action='store_true',
            ),
 
-    p.add_option_group ('bugs',
+    p.add_option_group (ly.display_encode (_ ('Bugs')),
                         description=(_ ('Report bugs via')
                                      + ''' http://post.gmane.org/post.php'''
                                      '''?group=gmane.comp.gnu.lilypond.bugs\n'''))
index bdb0637d17ee418424e1d1e83eb5fc91f96315e7..21d6f44c676098967ebf755e3eb62ef1d8ab9817 100644 (file)
@@ -107,25 +107,31 @@ def warranty ():
 
 def get_option_parser ():
     p = ly.get_option_parser (usage=_ ("%s [OPTION]... FILE") % 'lilypond-book',
-                              version="@TOPLEVEL_VERSION@",
-                              description=help_summary)
+                              description=help_summary,
+                              add_help_option=False)
 
     p.add_option ('-F', '--filter', metavar=_ ("FILTER"),
                   action="store",
                   dest="filter_cmd",
                   help=_ ("pipe snippets through FILTER [convert-ly -n -]"),
                   default=None)
+
     p.add_option ('-f', '--format',
                   help=_ ("use output format FORMAT (texi [default], texi-html, latex, html, docbook)"),
                   action='store')
-    
+
+    p.add_option("-h", "--help",
+                 action="help",
+                 help=_ ("show this help and exit"))
+
     p.add_option ("-I", '--include', help=_ ("add DIR to include path"),
                   metavar=_ ("DIR"),
                   action='append', dest='include_path',
                   default=[os.path.abspath (os.getcwd ())])
 
-    p.add_option ('--info-images-dir', help=_ ("format Texinfo output so that Info will "
-                                               "look for images of music in DIR"),
+    p.add_option ('--info-images-dir',
+                  help=_ ("format Texinfo output so that Info will "
+                          "look for images of music in DIR"),
                   metavar=_ ("DIR"),
                   action='store', dest='info_images_dir',
                   default='')
@@ -146,23 +152,32 @@ def get_option_parser ():
                   help = _ ("process ly_files using COMMAND FILE..."),
                   action='store', 
                   dest='process_cmd', default='lilypond -dbackend=eps')
+
     p.add_option ('--pdf',
                   action="store_true",
                   dest="create_pdf",
                   help=_ ("create PDF files for use with PDFTeX"),
                   default=False)
+
     p.add_option ('', '--psfonts', action="store_true", dest="psfonts",
                   help=_ ('''extract all PostScript fonts into INPUT.psfonts for LaTeX
 must use this with dvips -h INPUT.psfonts'''),
                   default=None)
+
     p.add_option ('-V', '--verbose', help=_ ("be verbose"),
                   action="store_true",
                   default=False,
                   dest="verbose")
+
+    p.version = "@TOPLEVEL_VERSION@"
+    p.add_option("--version",
+                 action="version",
+                 help=_ ("show version number and exit"))
+
     p.add_option ('-w', '--warranty',
                   help=_ ("show warranty and copyright"),
                   action='store_true')
-    p.add_option_group (_ ('Bugs'),
+    p.add_option_group (ly.display_encode (_ ('Bugs')),
                         description=(_ ("Report bugs via")
                                      + ''' http://post.gmane.org/post.php'''
                                      '''?group=gmane.comp.gnu.lilypond.bugs\n'''))
index eaf7f5d616e55fb0227260bda2ce6a965f3b8749..810b9108c6ef6102cae9b75b09a43e8aa561043d 100644 (file)
@@ -847,8 +847,8 @@ def convert_midi (in_file, out_file):
 
 def get_option_parser ():
     p = ly.get_option_parser (usage=_ ("%s [OPTION]... FILE") % 'midi2ly',
-                 version="midi2ly (LilyPond) @TOPLEVEL_VERSION@",
-                 description=_ ("Convert %s to LilyPond input.") % 'MIDI')
+                 description=_ ("Convert %s to LilyPond input.") % 'MIDI',
+                 add_help_option=False)
 
     p.add_option ('-a', '--absolute-pitches',
            action='store_true',
@@ -859,6 +859,9 @@ def get_option_parser ():
     p.add_option ('-e', '--explicit-durations',
            action='store_true',
            help=_ ("print explicit durations"))
+    p.add_option("-h", "--help",
+                 action="help",
+                 help=_ ("show this help and exit"))
     p.add_option('-k', '--key', help=_ ("set key: ALT=+sharps|-flats; MINOR=1"),
           metavar=_ ("ALT[:MINOR]"),
           default='0'),
@@ -876,19 +879,22 @@ def get_option_parser ():
     p.add_option ('-V', '--verbose', help=_ ("be verbose"),
            action='store_true'
            ),
+    p.version = "midi2ly (LilyPond) @TOPLEVEL_VERSION@"
+    p.add_option("--version",
+                 action="version",
+                 help=_ ("show version number and exit"))
     p.add_option ('-w', '--warranty', help=_ ("show warranty and copyright"),
            action='store_true',
            ),
     p.add_option ('-x', '--text-lyrics', help=_ ("treat every text as a lyric"),
            action='store_true')
 
-# urg, Python 2.5 optparse is broken, it doesn't accept Unicode strings
-    p.add_option_group (_ ("Examples").encode (sys.stdout.encoding),
+    p.add_option_group (ly.display_encode (_ ("Examples")),
               description = r'''
   midi2ly --key=-2:1 --duration-quant=32 \
     --allow-tuplet=4*2/3 --allow-tuplet=2*4/3 foo.midi
 ''')
-    p.add_option_group (_ ('Bugs').encode (sys.stdout.encoding),
+    p.add_option_group (ly.display_encode (_ ('Bugs')),
                         description=(_ ('Report bugs via')
                                      + ''' http://post.gmane.org/post.php'''
                                      '''?group=gmane.comp.gnu.lilypond.bugs\n'''))
index 1b8c568b5a588cb0622b0f121842fd357831f32c..ac0d30ba941213265189a4f9596a0694e12cc09b 100644 (file)
@@ -8,13 +8,13 @@ import string
 import codecs
 import zipfile
 import StringIO
-from gettext import gettext as _
 
 """
 @relocate-preamble@
 """
 
 import lilylib as ly
+_ = ly._
 
 import musicxml
 import musicexp
@@ -1800,7 +1800,14 @@ def get_all_voices (parts):
 
 def option_parser ():
     p = ly.get_option_parser (usage = _ ("musicxml2ly [options] FILE.xml"),
-                             version = ('''%prog (LilyPond) @TOPLEVEL_VERSION@\n\n'''
+                             description = _ ("Convert %s to LilyPond input.") % 'MusicXML' + "\n",
+                             add_help_option=False)
+
+    p.add_option("-h", "--help",
+                 action="help",
+                 help=_ ("show this help and exit"))
+
+    p.version = ('''%prog (LilyPond) @TOPLEVEL_VERSION@\n\n'''
                                       +
 _ ("""This program is free software.  It is covered by the GNU General Public
 License and you are welcome to change it and/or distribute copies of it
@@ -1811,8 +1818,11 @@ Copyright (c) 2005--2008 by
     Han-Wen Nienhuys <hanwen@xs4all.nl>,
     Jan Nieuwenhuizen <janneke@gnu.org> and
     Reinhold Kainhofer <reinhold@kainhofer.com>
-"""),
-                             description = _ ("Convert %s to LilyPond input.") % 'MusicXML' + "\n")
+""")
+    p.add_option("--version",
+                 action="version",
+                 help=_ ("show version number and exit"))
+
     p.add_option ('-v', '--verbose',
                   action = "store_true",
                   dest = 'verbose',
@@ -1822,35 +1832,35 @@ Copyright (c) 2005--2008 by
                   action = "store_true",
                   default = False,
                   dest = "use_lxml",
-                  help = _ ("Use lxml.etree; uses less memory and cpu time."))
+                  help = _ ("use lxml.etree; uses less memory and cpu time"))
 
     p.add_option ('-z', '--compressed',
                   action = "store_true",
                   dest = 'compressed',
                   default = False,
-                  help = _ ("Input file is a zip-compressed MusicXML file."))
+                  help = _ ("input file is a zip-compressed MusicXML file"))
 
     p.add_option ('-r', '--relative',
                   action = "store_true",
                   default = True,
                   dest = "relative",
-                  help = _ ("Convert pitches in relative mode. (Default)"))
+                  help = _ ("convert pitches in relative mode (default)"))
 
     p.add_option ('-a', '--absolute',
                   action = "store_false",
                   dest = "relative",
-                  help = _ ("Convert pitches in absolute mode."))
+                  help = _ ("convert pitches in absolute mode"))
 
     p.add_option ('-l', '--language',
                   metavar = _ ("LANG"),
                   action = "store",
-                  help = _ ("Use a different language file 'LANG.ly' and corresponding pitch names, e.g. 'deutsch' for deutsch.ly."))
+                  help = _ ("use a different language file 'LANG.ly' and corresponding pitch names, e.g. 'deutsch' for deutsch.ly"))
 
     p.add_option ('--nd', '--no-articulation-directions', 
                   action = "store_false",
                   default = True,
                   dest = "convert_directions",
-                  help = _ ("Do not convert directions (^, _ or -) for articulations, dynamics, etc."))
+                  help = _ ("do not convert directions (^, _ or -) for articulations, dynamics, etc."))
 
     p.add_option ('-o', '--output',
                   metavar = _ ("FILE"),
@@ -1859,8 +1869,8 @@ Copyright (c) 2005--2008 by
                   type = 'string',
                   dest = 'output_name',
                   help = _ ("set output filename to FILE"))
-    p.add_option_group ( _ ('Bugs'),
-                        description = ( _ ("Report bugs via")
+    p.add_option_group (ly.display_encode (_ ('Bugs')),
+                        description = (_ ("Report bugs via")
                                      + ''' http://post.gmane.org/post.php'''
                                      '''?group=gmane.comp.gnu.lilypond.bugs\n'''))
     return p