Python 3 gettext无法用于argparse [英] Python 3 gettext not working for argparse
本文介绍了Python 3 gettext无法用于argparse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将'usage:'转换为'foobar'.
I want to translate 'usage: ' into 'foobar'.
print(gettext.find('test', 'i18n', ['en_US']))
translator = gettext.translation('test', localedir='i18n', languages=['en_US'])
translator.install()
print(_('usage: '))
parser = argparse.ArgumentParser(prog="jcheq.py",
usage="%(prog)s [opciones] [paths...]\nThe paths are optional; if not given . is "
"used.",
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
但是它输出:
~/Desktop/Proyectos/UNPAZ/jcheq/jcheq$ python3 jcheq.py --help
i18n/en_US/LC_MESSAGES/test.mo
foobar:
usage: jcheq.py [opciones] [paths...]
The paths are optional; if not given . is used.
Opciones:
-h, --help Mostrar este mensaje de ayuda y salir.
-m, --modified show last modified date/time (default: False)
似乎它适用于我的字符串,但不适用于argparse的字符串:
Seems that it is working for my string, but not for argparse's one:
argparse.py:292 aprox
def _format_usage(self, usage, actions, groups, prefix):
if prefix is None:
prefix = _('usage: ')
推荐答案
查看全文