[UI] Enable translation of argparse help strings
This commit is contained in:
parent
64ac5fdf73
commit
9a051b6979
|
@ -71,8 +71,8 @@ class DelugeTextHelpFormatter(argparse.RawDescriptionHelpFormatter):
|
||||||
default = action.dest.upper()
|
default = action.dest.upper()
|
||||||
args_string = self._format_args(action, default)
|
args_string = self._format_args(action, default)
|
||||||
opt = ", ".join(action.option_strings)
|
opt = ", ".join(action.option_strings)
|
||||||
parts.append('%s %s' % (opt, args_string))
|
parts.append("%s %s" % (opt, args_string))
|
||||||
return ', '.join(parts)
|
return ", ".join(parts)
|
||||||
|
|
||||||
|
|
||||||
class HelpAction(argparse._HelpAction):
|
class HelpAction(argparse._HelpAction):
|
||||||
|
@ -94,24 +94,24 @@ class BaseArgParser(argparse.ArgumentParser):
|
||||||
super(BaseArgParser, self).__init__(*args, add_help=False, **kwargs)
|
super(BaseArgParser, self).__init__(*args, add_help=False, **kwargs)
|
||||||
|
|
||||||
self.common_setup = False
|
self.common_setup = False
|
||||||
self.group = self.add_argument_group('Common Options')
|
self.group = self.add_argument_group(_("Common Options"))
|
||||||
self.group.add_argument('--version', action='version', version='%(prog)s ' + get_version(),
|
self.group.add_argument("--version", action="version", version="%(prog)s " + get_version(),
|
||||||
help="Show program's version number and exit")
|
help=_("Show program's version info and exit"))
|
||||||
self.group.add_argument("-c", "--config", action="store", metavar='<config>',
|
self.group.add_argument("-c", "--config", action="store", metavar="<config>",
|
||||||
help="Set the config directory path")
|
help=_("Set the config directory path"))
|
||||||
self.group.add_argument("-l", "--logfile", action="store", metavar='<logfile>',
|
self.group.add_argument("-l", "--logfile", action="store", metavar="<logfile>",
|
||||||
help="Output to designated logfile instead of stdout")
|
help=_("Output to specified logfile instead of stdout"))
|
||||||
self.group.add_argument("-L", "--loglevel", action="store", choices=deluge.log.levels, metavar='<level>',
|
self.group.add_argument("-L", "--loglevel", action="store", choices=deluge.log.levels, metavar="<level>",
|
||||||
help="Set the log level: %s" % ", ".join(deluge.log.levels))
|
help=_("Set the log level: %s" % ", ".join(deluge.log.levels)))
|
||||||
self.group.add_argument("--logrotate", action="store", nargs="?", const="2M", metavar='<max size>',
|
self.group.add_argument("--logrotate", action="store", nargs="?", const="2M", metavar="<max size>",
|
||||||
help="Enable logfile rotation, takes an optional maximum logfile size, "
|
help=_("Enable logfile rotation, with optional maximum logfile size, \
|
||||||
"default: %(const)s (Logfile rotatation count is 5)")
|
default: %(const)s (Logfile rotation count is 5)"))
|
||||||
self.group.add_argument("-q", "--quiet", action="store_true", default=False,
|
self.group.add_argument("-q", "--quiet", action="store_true", default=False,
|
||||||
help="Sets the log level to 'none', this is the same as `-L none`")
|
help=_("Quieten logging output, equal to `--loglevel none`"))
|
||||||
self.group.add_argument("--profile", metavar="<results file>", action="store", nargs="?", default=False,
|
self.group.add_argument("--profile", metavar="<results file>", action="store", nargs="?", default=False,
|
||||||
help="Profile %(prog)s with cProfile. Prints results to stdout"
|
help=_("Profile %(prog)s with cProfile. Prints results to stdout \
|
||||||
"unless a filename is specififed")
|
unless a filename is specified"))
|
||||||
self.group.add_argument("-h", "--help", action=HelpAction, help='Show this help message and exit')
|
self.group.add_argument("-h", "--help", action=HelpAction, help=_("Show this help message and exit"))
|
||||||
|
|
||||||
def parse_args(self, *args):
|
def parse_args(self, *args):
|
||||||
options, remaining = super(BaseArgParser, self).parse_known_args(*args)
|
options, remaining = super(BaseArgParser, self).parse_known_args(*args)
|
||||||
|
@ -125,10 +125,10 @@ class BaseArgParser(argparse.ArgumentParser):
|
||||||
if options.loglevel:
|
if options.loglevel:
|
||||||
options.loglevel = options.loglevel.lower()
|
options.loglevel = options.loglevel.lower()
|
||||||
|
|
||||||
logfile_mode = 'w'
|
logfile_mode = "w"
|
||||||
logrotate = options.logrotate
|
logrotate = options.logrotate
|
||||||
if options.logrotate:
|
if options.logrotate:
|
||||||
logfile_mode = 'a'
|
logfile_mode = "a"
|
||||||
logrotate = common.parse_human_size(options.logrotate)
|
logrotate = common.parse_human_size(options.logrotate)
|
||||||
|
|
||||||
# Setup the logger
|
# Setup the logger
|
||||||
|
|
|
@ -31,8 +31,8 @@ class UI(object):
|
||||||
|
|
||||||
def __init__(self, name="gtk", parser=None):
|
def __init__(self, name="gtk", parser=None):
|
||||||
self.__name = name
|
self.__name = name
|
||||||
self.__parser = parser if parser else BaseArgParser()
|
|
||||||
deluge.common.setup_translations(setup_pygtk=(name == "gtk"))
|
deluge.common.setup_translations(setup_pygtk=(name == "gtk"))
|
||||||
|
self.__parser = parser if parser else BaseArgParser()
|
||||||
|
|
||||||
def parse_args(self, args=None):
|
def parse_args(self, args=None):
|
||||||
options = self.parser.parse_args(args)
|
options = self.parser.parse_args(args)
|
||||||
|
|
|
@ -33,25 +33,25 @@ def start_ui():
|
||||||
|
|
||||||
# Setup the argument parser
|
# Setup the argument parser
|
||||||
parser = BaseArgParser()
|
parser = BaseArgParser()
|
||||||
group = parser.add_argument_group(_("Default Options"))
|
group = parser.add_argument_group(_("UI Options"))
|
||||||
|
|
||||||
ui_entrypoints = dict([(entrypoint.name, entrypoint.load())
|
ui_entrypoints = dict([(entrypoint.name, entrypoint.load())
|
||||||
for entrypoint in pkg_resources.iter_entry_points('deluge.ui')])
|
for entrypoint in pkg_resources.iter_entry_points("deluge.ui")])
|
||||||
|
|
||||||
cmd_help = ['The UI that you wish to launch. The UI choices are:']
|
cmd_help = [_("The UI that you wish to launch. The UI choices are:")]
|
||||||
max_len = 0
|
max_len = 0
|
||||||
for k, v in ui_entrypoints.iteritems():
|
for k, v in ui_entrypoints.iteritems():
|
||||||
cmdline = getattr(v, 'cmdline', "")
|
cmdline = getattr(v, "cmdline", "")
|
||||||
max_len = max(max_len, len(cmdline))
|
max_len = max(max_len, len(cmdline))
|
||||||
|
|
||||||
cmd_help.extend(["%s -- %s" % (k, getattr(v, 'cmdline', "")) for k, v in ui_entrypoints.iteritems()])
|
cmd_help.extend(["%s -- %s" % (k, getattr(v, "cmdline", "")) for k, v in ui_entrypoints.iteritems()])
|
||||||
|
|
||||||
parser.add_argument("-u", "--ui", action="store",
|
group.add_argument("-u", "--ui", action="store",
|
||||||
choices=ui_entrypoints.keys(), help="\n* ".join(cmd_help))
|
choices=ui_entrypoints.keys(), help="\n* ".join(cmd_help))
|
||||||
group.add_argument("-a", "--args", action="store",
|
group.add_argument("-a", "--args", action="store",
|
||||||
help='Arguments to pass to the UI. Multiple args must be quoted, e.g. -a "--option args"')
|
help=_('Arguments to pass to the UI. Multiple args must be quoted, e.g. -a "--option args"'))
|
||||||
group.add_argument("-s", "--set-default-ui", dest="default_ui", choices=ui_entrypoints.keys(),
|
group.add_argument("-s", "--set-default-ui", dest="default_ui", choices=ui_entrypoints.keys(),
|
||||||
help="Sets the default UI to be run when no UI is specified", action="store")
|
help=_("Sets the default UI to be run when no UI is specified"), action="store")
|
||||||
|
|
||||||
options = parser.parse_args(deluge.common.unicode_argv()[1:])
|
options = parser.parse_args(deluge.common.unicode_argv()[1:])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue