~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/option.py

  • Committer: Jonathan Riddell
  • Date: 2011-09-16 11:13:47 UTC
  • mto: This revision was merged to the branch mainline in revision 6144.
  • Revision ID: jriddell@canonical.com-20110916111347-fyjk426bkl0jrbfu
gettext() show_warning usage

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from bzrlib import (
26
26
    errors,
27
27
    revisionspec,
 
28
    i18n,
28
29
    )
29
30
""")
30
31
 
429
430
 
430
431
    DEFAULT_VALUE = object()
431
432
 
 
433
    def __init__(self):
 
434
        optparse.OptionParser.__init__(self)
 
435
        self.formatter = GettextIndentedHelpFormatter()
 
436
 
432
437
    def error(self, message):
433
438
        raise errors.BzrCommandError(message)
434
439
 
 
440
class GettextIndentedHelpFormatter(optparse.IndentedHelpFormatter):
 
441
    """Adds gettext() call to format_option()"""
 
442
    def __init__(self):
 
443
        optparse.IndentedHelpFormatter.__init__(self)
 
444
 
 
445
    def format_option(self, option):
 
446
        """code taken from Python's optparse.py"""
 
447
        if option.help:
 
448
            option.help = i18n.gettext(option.help)
 
449
        return optparse.IndentedHelpFormatter.format_option(self, option)
435
450
 
436
451
def get_optparser(options):
437
452
    """Generate an optparse parser for bzrlib-style options"""