From: John Mandereau Date: Wed, 13 Feb 2008 20:48:30 +0000 (+0100) Subject: Improve Python scripts localization X-Git-Tag: release/2.11.40-1~3^2~12^2~4 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=703ad9d9cf5b48abfbd14cac074859189f4cda81;p=lilypond.git Improve Python scripts localization * 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. --- diff --git a/python/lilylib.py b/python/lilylib.py index ec38d70d73..cfa5e67d0a 100644 --- a/python/lilylib.py +++ b/python/lilylib.py @@ -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) diff --git a/python/musicexp.py b/python/musicexp.py index 07af416ab7..b266830d07 100644 --- a/python/musicexp.py +++ b/python/musicexp.py @@ -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 {') diff --git a/python/musicxml.py b/python/musicxml.py index f96895f638..a6b8c2ab41 100644 --- a/python/musicxml.py +++ b/python/musicxml.py @@ -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): diff --git a/scripts/abc2ly.py b/scripts/abc2ly.py index 2693817e92..a1fbf38a71 100644 --- a/scripts/abc2ly.py +++ b/scripts/abc2ly.py @@ -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''')) diff --git a/scripts/convert-ly.py b/scripts/convert-ly.py index 6d7eda4a41..d4e4ceecc2 100644 --- a/scripts/convert-ly.py +++ b/scripts/convert-ly.py @@ -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''')) diff --git a/scripts/etf2ly.py b/scripts/etf2ly.py index dd431d699a..4e2fcc7a11 100644 --- a/scripts/etf2ly.py +++ b/scripts/etf2ly.py @@ -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''')) diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index bdb0637d17..21d6f44c67 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -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''')) diff --git a/scripts/midi2ly.py b/scripts/midi2ly.py index eaf7f5d616..810b9108c6 100644 --- a/scripts/midi2ly.py +++ b/scripts/midi2ly.py @@ -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''')) diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index 1b8c568b5a..ac0d30ba94 100644 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -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 , Jan Nieuwenhuizen and Reinhold Kainhofer -"""), - 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