Running the following:
import argparse
class MyHelpFormatter(argparse.HelpFormatter):
def __init__(self, *args, **kwargs):
super(MyHelpFormatter, self).__init__(*args, **kwargs)
def _format_usage(self, usage, actions, groups, prefix):
return super(MyHelpFormatter, self)._format_usage(
usage, actions, groups, prefix if prefix else "bla: ")
class MyArgumentParser(argparse.ArgumentParser):
def __init__(self, *args, **kwargs):
kwargs['formatter_class']=MyHelpFormatter
super(MyArgumentParser, self).__init__(*args, **kwargs)
p = MyArgumentParser(description='Foo')
p.add_argument('foo', type=str)
print p.parse_args()
prints
python myargparse.py --help
bla: myargparse.py [-h] foo
Foo
positional arguments:
foo
optional arguments:
-h, --help show this help message and exit
_('usage: ')
references gettext
. In argparse.py
, at the top, you have:
from gettext import gettext as _
You can muck around with gettext
a bit.
Given a .po
file:
msgid "usage: "
msgstr "foobar: "
You can convert it to a .mo
file (for example here).
Afterwards (where ./foo/LC_MESSAGES/messages.mo
is the result of compiling the .po
):
~/Desktop> find . -name *mo
./foo/LC_MESSAGES/messages.mo
~/Desktop> cat myargparse2.py
import argparse
import gettext
gettext.bindtextdomain(gettext.textdomain(), '.')
p = argparse.ArgumentParser(description='Foo')
p.add_argument('foo', type=str)
print p.parse_args()
~/Desktop> LANGUAGE=foo python myargparse2.py
foobar: myargparse2.py [-h] foo
myargparse2.py: error: too few arguments
Use your desired languages instead of foo
.