I have several command-line python scripts that handle several parameters to invoke them, this I resolve through argparse , which is very simple, however this library has some messages in English (at least in python 3.4) that I would like to translate, let's see an example:
# -*- coding: utf-8 -*-
import argparse
def init_argparse():
cmdparser = argparse.ArgumentParser(prog='programa', description='descripcion')
cmdparser.add_argument('archivo', type=str, nargs='?', help="Archivo de input", metavar="\"archivo a interpretar\"")
cmdparser.add_argument("-v", "--version", action='version', help="mostrar la versión y salir", version="1.1.1")
return cmdparser
if __name__ == "__main__":
cmdparser = init_argparse()
try:
args = cmdparser.parse_args()
except IOError as msg:
cmdparser.error(str(msg))
sys.exit(-1)
If this Script is executed as python miscript.py --help
, I get the following output:
usage: programa [-h] [-v] ["archivo a interpretar"]
descripcion
positional arguments:
"archivo a interpretar"
Archivo de input
optional arguments:
-h, --help show this help message and exit
-v, --version mostrar la versión y salir
As you can see there are texts like "usage", "positional arguments", "optional arguments" and others that are in English. How can I translate them so that the interface is consistent?