Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #27935
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: argparse localization support |
| Date | 2012-08-26 19:21 +0200 |
| Organization | None |
| References | <CAMw+j7K39W3xVy7XznB87cnMs6WVvkGcnV_q7mxexnCwEoNTkQ@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3845.1346001704.4697.python-list@python.org> (permalink) |
Kwpolska wrote:
> I am using argparse in my project. I want to localize it, but it
> seems to be impossible to change some things. See this, for example:
>
> usage: trash [-h] [-V] [-e] [-l] [-r] [-v] [-w] [PLIK [PLIK ...]]
>
> Trashman — menedżer śmietnika XDG w Pythonie.
>
> positional arguments:
> PLIK pliki do wyrzucenia
>
> optional arguments:
> -h, --help show this help message and exit
> -V, --version show program's version number and exit
>
> (a snippet of help for Trashman, a Python trash manager, with
> LANG='pl_PL.UTF-8'; https://github.com/Kwpolska/trashman )
>
> Anyways, you can see that -h and -V (added semi-automatically by
> argparse), “usage:” and “positional/optional arguments:” are still in
> English. It doesn’t look very professional. Also, I want to use
> fancy UTF-8 characters. Is there a way to fix that?
I don't know much about gettext, but the following suggests that most
strings in argparse are properly wrapped:
$ cat localize_argparse.py
import gettext
def my_gettext(s):
return s.upper()
gettext.gettext = my_gettext
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-V", action="version")
args = parser.parse_args()
$ python localize_argparse.py -h
USAGE: localize_argparse.py [-h] [-V]
OPTIONAL ARGUMENTS:
-h, --help SHOW THIS HELP MESSAGE AND EXIT
-V show program's version number and exit
The workaround for the "-V" option would be to add the help message
explicitly
parser.add_argument("-V", ..., help=_("show..."))
You still have to provide all translations yourself.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: argparse localization support Peter Otten <__peter__@web.de> - 2012-08-26 19:21 +0200
csiph-web