/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/option.py

Implement command help l10n.

Show diffs side-by-side

added added

removed removed

Lines of Context:
203
203
        else:
204
204
            return 'no-' + self.name
205
205
 
206
 
    def add_option(self, parser, short_name):
 
206
    @staticmethod
 
207
    def get_gettext():
 
208
        """Returns the gettext function used to translate this Option's help.
 
209
 
 
210
        NOTE: Options provided by third party plugins should override this to
 
211
        use own i18n system.
 
212
        """
 
213
        from bzrlib.i18n import gettext
 
214
        return gettext
 
215
 
 
216
    def add_option(self, parser, short_name, l10n=False):
207
217
        """Add this option to an Optparse parser"""
 
218
        if l10n:
 
219
            gettext = self.get_gettext()
 
220
        else:
 
221
            gettext = lambda x: x
208
222
        option_strings = ['--%s' % self.name]
209
223
        if short_name is not None:
210
224
            option_strings.append('-%s' % short_name)
211
225
        if self.hidden:
212
226
            help = optparse.SUPPRESS_HELP
213
227
        else:
214
 
            help = self.help
 
228
            help = gettext(self.help)
215
229
        optargfn = self.type
216
230
        if optargfn is None:
217
231
            parser.add_option(action='callback',
312
326
 
313
327
    def __init__(self, name, help, registry=None, converter=None,
314
328
        value_switches=False, title=None, enum_switch=True,
315
 
        lazy_registry=None):
 
329
        lazy_registry=None, short_name=None):
316
330
        """
317
331
        Constructor.
318
332
 
329
343
        :param lazy_registry: A tuple of (module name, attribute name) for a
330
344
            registry to be lazily loaded.
331
345
        """
332
 
        Option.__init__(self, name, help, type=self.convert)
 
346
        Option.__init__(self, name, help, type=self.convert, short_name=short_name)
333
347
        self._registry = registry
334
348
        if registry is None:
335
349
            if lazy_registry is None:
426
440
        raise errors.BzrCommandError(message)
427
441
 
428
442
 
429
 
def get_optparser(options):
 
443
def get_optparser(options, l10n=False):
430
444
    """Generate an optparse parser for bzrlib-style options"""
431
445
 
432
446
    parser = OptionParser()
433
447
    parser.remove_option('--help')
434
448
    for option in options.itervalues():
435
 
        option.add_option(parser, option.short_name())
 
449
        option.add_option(parser, option.short_name(), l10n)
436
450
    return parser
437
451
 
438
452
 
530
544
               short_name='m',
531
545
               help='Message string.')
532
546
_global_option('no-recurse')
 
547
_global_option('null', short_name='0',
 
548
                 help='Use an ASCII NUL (\\0) separator rather than '
 
549
                      'a newline.')
533
550
_global_option('profile',
534
551
               help='Show performance profiling information.')
535
552
_global_option('revision',
570
587
_global_option('dry-run',
571
588
               help="Show what would be done, but don't actually do anything.")
572
589
_global_option('name-from-revision', help='The path name in the old tree.')
 
590
_global_option('directory', short_name='d', type=unicode,
 
591
               help='Branch to operate on, instead of working directory')
573
592
 
574
593
diff_writer_registry = _mod_registry.Registry()
575
594
diff_writer_registry.register('plain', lambda x: x, 'Plaintext diff output.')