How to localize Python argparse module without fixing it?

A localized command line application looks strange when some part of the messages is in the user's language and some other parts in English.

I do not know if I messed up anything when I installed Python 3 from the source code, it seems that there are no files *.mo, therefore argparse(among all) is not localization.

The API does not seem to offer a way to localize. Or did I miss this?

I could pay argparse.py, but I won’t, because I want it to be portable, and I’m out of order asking users to fix their Python installation.

The question is fewer words: how to localize argpasewithout fixing the standard Python library?

A related question : is this possible?

+4
source share
1 answer

By default, it argparseuses the module gettextfor translating messages so that you can easily translate them if you want.

To generate files *.pot(which you can convert to files *.moafter translation), you can use a program pygettextthat is available in the built-in module gettextin python.

Using:

python pygettext.py argparse.py

This will create messages.potwhich you can translate, then just create .mo(many ways to do this, just google).

pygettext . Python : https://docs.python.org/2/library/gettext.html#internationalizing-your-programs-and-modules

+3

All Articles