/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

s/i18n/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):
207
 
        """Add this option to an Optparse parser"""
 
206
    @property
 
207
    def gettext(self):
 
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):
 
217
        """Add this option to an Optparse parser.
 
218
        
 
219
        If `l10n` is true, messages passed to Optparse
 
220
        """
208
221
        option_strings = ['--%s' % self.name]
209
222
        if short_name is not None:
210
223
            option_strings.append('-%s' % short_name)
211
224
        if self.hidden:
212
225
            help = optparse.SUPPRESS_HELP
213
226
        else:
214
 
            help = self.help
 
227
            help = self.gettext(self.help) if l10n else self.help
215
228
        optargfn = self.type
216
229
        if optargfn is None:
217
230
            parser.add_option(action='callback',
268
281
    sets the value of the 'foo' option to ['c'].
269
282
    """
270
283
 
271
 
    def add_option(self, parser, short_name):
 
284
    def add_option(self, parser, short_name, l10n=False):
272
285
        """Add this option to an Optparse parser."""
273
286
        option_strings = ['--%s' % self.name]
274
287
        if short_name is not None:
275
288
            option_strings.append('-%s' % short_name)
 
289
        help = self.gettext(self.help) if l10n else self.help
276
290
        parser.add_option(action='callback',
277
291
                          callback=self._optparse_callback,
278
292
                          type='string', metavar=self.argname.upper(),
279
 
                          help=self.help, dest=self._param_name, default=[],
280
 
                          *option_strings)
 
293
                          help=help, dest=self._param_name,
 
294
                          default=[], *option_strings)
281
295
 
282
296
    def _optparse_callback(self, option, opt, value, parser):
283
297
        values = getattr(parser.values, self._param_name)
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:
374
388
        return RegistryOption(name_, help, reg, title=title,
375
389
            value_switches=value_switches, enum_switch=enum_switch)
376
390
 
377
 
    def add_option(self, parser, short_name):
 
391
    def add_option(self, parser, short_name, l10n=False):
378
392
        """Add this option to an Optparse parser"""
379
393
        if self.value_switches:
380
394
            parser = parser.add_option_group(self.title)
387
401
                    help = optparse.SUPPRESS_HELP
388
402
                else:
389
403
                    help = self.registry.get_help(key)
 
404
                    if l10n:
 
405
                        help = self.gettext(help)
390
406
                parser.add_option(action='callback',
391
407
                              callback=self._optparse_value_callback(key),
392
408
                                  help=help,
426
442
        raise errors.BzrCommandError(message)
427
443
 
428
444
 
429
 
def get_optparser(options):
 
445
def get_optparser(options, l10n=False):
430
446
    """Generate an optparse parser for bzrlib-style options"""
431
447
 
432
448
    parser = OptionParser()
433
449
    parser.remove_option('--help')
434
450
    for option in options.itervalues():
435
 
        option.add_option(parser, option.short_name())
 
451
        option.add_option(parser, option.short_name(), l10n)
436
452
    return parser
437
453
 
438
454
 
530
546
               short_name='m',
531
547
               help='Message string.')
532
548
_global_option('no-recurse')
 
549
_global_option('null', short_name='0',
 
550
                 help='Use an ASCII NUL (\\0) separator rather than '
 
551
                      'a newline.')
533
552
_global_option('profile',
534
553
               help='Show performance profiling information.')
535
554
_global_option('revision',
570
589
_global_option('dry-run',
571
590
               help="Show what would be done, but don't actually do anything.")
572
591
_global_option('name-from-revision', help='The path name in the old tree.')
 
592
_global_option('directory', short_name='d', type=unicode,
 
593
               help='Branch to operate on, instead of working directory')
573
594
 
574
595
diff_writer_registry = _mod_registry.Registry()
575
596
diff_writer_registry.register('plain', lambda x: x, 'Plaintext diff output.')