/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/commands.py

Implement command help l10n.

Show diffs side-by-side

added added

removed removed

Lines of Context:
492
492
            usage help (e.g. Purpose, Usage, Options) with a
493
493
            message explaining how to obtain full help.
494
494
        """
 
495
        from bzrlib.i18n import gettext   # gettext() for fixed string
 
496
        cmd_gettext = self.get_gettext()  # gettext() for command help
495
497
        doc = self.help()
496
 
        if not doc:
497
 
            doc = "No help for this command."
 
498
        if doc:
 
499
            # NOTE: If cmd_gettext translates ':Usage:\n', the section will
 
500
            # be shown after "Description" section.
 
501
            # Additionally, ZzzTranslation translates ':Label...' into
 
502
            # 'zz{{:Label...}}'. So all sections are broken and shown in
 
503
            # the "Description" section.
 
504
            doc = cmd_gettext(doc)
 
505
        else:
 
506
            doc = gettext("No help for this command.")
498
507
 
499
508
        # Extract the summary (purpose) and sections out from the text
500
509
        purpose,sections,order = self._get_help_parts(doc)
507
516
 
508
517
        # The header is the purpose and usage
509
518
        result = ""
510
 
        result += ':Purpose: %s\n' % purpose
 
519
        result += ':%s: %s\n' % (gettext('Purpose'), purpose)
511
520
        if usage.find('\n') >= 0:
512
 
            result += ':Usage:\n%s\n' % usage
 
521
            result += ':%s:\n%s\n' % (gettext('Usage'), usage)
513
522
        else:
514
 
            result += ':Usage:   %s\n' % usage
 
523
            result += ':%s:   %s\n' % (gettext('Usage'), usage)
515
524
        result += '\n'
516
525
 
517
526
        # Add the options
519
528
        # XXX: optparse implicitly rewraps the help, and not always perfectly,
520
529
        # so we get <https://bugs.launchpad.net/bzr/+bug/249908>.  -- mbp
521
530
        # 20090319
522
 
        options = option.get_optparser(self.options()).format_option_help()
 
531
        options = option.get_optparser(self.options(), True)
 
532
        options = options.format_option_help()
523
533
        # FIXME: According to the spec, ReST option lists actually don't
524
534
        # support options like --1.14 so that causes syntax errors (in Sphinx
525
535
        # at least).  As that pattern always appears in the commands that
528
538
        # don't have to do that too often -- vila 20110514
529
539
        if not plain and options.find('  --1.14  ') != -1:
530
540
            options = options.replace(' format:\n', ' format::\n\n', 1)
531
 
        if options.startswith('Options:'):
532
 
            result += ':' + options
533
 
        elif options.startswith('options:'):
534
 
            # Python 2.4 version of optparse
535
 
            result += ':Options:' + options[len('options:'):]
 
541
        if options.startswith('Options:') or options.startswith('options:'):
 
542
            # Python 2.4 version of optparse uses 'options'.
 
543
            result += ':%s:%s' % (gettext('Options'), options[len('options:'):])
536
544
        else:
537
545
            result += options
538
546
        result += '\n'
543
551
            if sections.has_key(None):
544
552
                text = sections.pop(None)
545
553
                text = '\n  '.join(text.splitlines())
546
 
                result += ':%s:\n  %s\n\n' % ('Description',text)
 
554
                result += ':%s:\n  %s\n\n' % (gettext('Description'),text)
547
555
 
548
556
            # Add the custom sections (e.g. Examples). Note that there's no need
549
557
            # to indent these as they must be indented already in the source.
550
558
            if sections:
551
559
                for label in order:
552
 
                    if sections.has_key(label):
553
 
                        result += ':%s:\n%s\n' % (label,sections[label])
 
560
                    if label in sections:
 
561
                        result += ':%s:\n%s\n' % (label, sections[label])
554
562
                result += '\n'
555
563
        else:
556
 
            result += ("See bzr help %s for more details and examples.\n\n"
 
564
            result += (gettext("See bzr help %s for more details and examples.\n\n")
557
565
                % self.name())
558
566
 
559
567
        # Add the aliases, source (plug-in) and see also links, if any
560
568
        if self.aliases:
561
 
            result += ':Aliases:  '
 
569
            result += ':%s:  ' % gettext('Aliases')
562
570
            result += ', '.join(self.aliases) + '\n'
563
571
        plugin_name = self.plugin_name()
564
572
        if plugin_name is not None:
577
585
                        link_text = ":doc:`%s <%s-help>`" % (item, item)
578
586
                        see_also_links.append(link_text)
579
587
                see_also = see_also_links
580
 
            result += ':See also: '
 
588
            result += ':%s: ' % gettext('See also')
581
589
            result += ', '.join(see_also) + '\n'
582
590
 
583
591
        # If this will be rendered as plain text, convert it
668
676
 
669
677
        # Process the standard options
670
678
        if 'help' in opts:  # e.g. bzr add --help
671
 
            sys.stdout.write(self.get_help_text())
 
679
            self._setup_outf()
 
680
            self.outf.write(self.get_help_text())
672
681
            return 0
673
682
        if 'usage' in opts:  # e.g. bzr add --usage
674
683
            sys.stdout.write(self.get_help_text(verbose=False))
758
767
            return None
759
768
        return getdoc(self)
760
769
 
 
770
    @staticmethod
 
771
    def get_gettext():
 
772
        """Returns the gettext function used to translate this command's help.
 
773
 
 
774
        NOTE: Commands provided by plugins should override this to use own
 
775
        i18n system.
 
776
        """
 
777
        from bzrlib.i18n import gettext
 
778
        return gettext
 
779
 
761
780
    def name(self):
762
781
        """Return the canonical name for this command.
763
782
 
1048
1067
    argv = _specified_or_unicode_argv(argv)
1049
1068
    trace.mutter("bzr arguments: %r", argv)
1050
1069
 
1051
 
    opt_lsprof = opt_profile = opt_no_plugins = opt_builtin =  \
1052
 
                opt_no_aliases = False
 
1070
    opt_lsprof = opt_profile = opt_no_plugins = opt_builtin = \
 
1071
            opt_no_i18n = opt_no_aliases = False
1053
1072
    opt_lsprof_file = opt_coverage_dir = None
1054
1073
 
1055
1074
    # --no-plugins is handled specially at a very early stage. We need
1072
1091
            opt_no_plugins = True
1073
1092
        elif a == '--no-aliases':
1074
1093
            opt_no_aliases = True
 
1094
        elif a == '--no-i18n':
 
1095
            opt_no_i18n = True
1075
1096
        elif a == '--builtin':
1076
1097
            opt_builtin = True
1077
1098
        elif a == '--concurrency':
1089
1110
        i += 1
1090
1111
 
1091
1112
    debug.set_debug_flags_from_config()
 
1113
    if not opt_no_i18n:
 
1114
        from bzrlib import i18n
 
1115
        if 'i18n' in debug.debug_flags:
 
1116
            i18n.install_zzz()
 
1117
        else:
 
1118
            i18n.install()
1092
1119
 
1093
1120
    if not opt_no_plugins:
1094
1121
        load_plugins()