How to make python's argparse generate Non-English text?

前端 未结 5 808
星月不相逢
星月不相逢 2020-12-31 12:50

The argparse module \"automatically generates help and usage messages\". I can give Non-English names to the arguments and provide Non-English help texts; b

5条回答
  •  既然无缘
    2020-12-31 13:51

    Here is a solution with French translation, where one creates a conversion dict that holds the translation for the encountered English keywords

    def convertArgparseMessages(s):
        subDict = \
        {'positional arguments':'Arguments positionnels',
        'optional arguments':'Arguments optionnels',
        'show this help message and exit':'Affiche ce message et quitte'}
        if s in subDict:
            s = subDict[s]
        return s
    gettext.gettext = convertArgparseMessages
    import argparse
    

提交回复
热议问题