This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jdetrey
Recipients bethard, jdetrey, paul.j3, proski, thorsten
Date 2021-08-08.13:34:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1628429687.28.0.215712550073.issue16786@roundup.psfhosted.org>
In-reply-to
Content
Dear all,

As commented on PR 12711 (https://github.com/python/cpython/pull/12711#pullrequestreview-724899323), there is a slight issue with the proposed patch, as it translates the `--version` help string as soon as the `argparse` module is imported (at which point the programmer might not have correctly initialized the `gettext` global domain yet). The suggested modification of PR 12711 should fix this, so that the translation only happens when an instance of `_VersionAction` is actually created:
```
diff a/Lib/argparse.py b/Lib/argparse.py
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -1042,7 +1042,9 @@ def __init__(self,
                  version=None,
                  dest=SUPPRESS,
                  default=SUPPRESS,
-                 help="show program's version number and exit"):
+                 help=None):
+        if help is None:
+            help = _("show program's version number and exit")
         super(_VersionAction, self).__init__(
             option_strings=option_strings,
             dest=dest,
```

However, I'm not sure I understand correctly Pavel's comment as to why merging this patch would make some old programs lose their translation for this string: since `argparse` does not itself provide any translation, it is up to the programmers to provide `gettext` translations for `argparse` strings as well. Adding the call to `_()` here seems harmless to me:
- if a program already has a `gettext` translation string for "show program's version number and exit", it will be used, as expected;
- otherwise, if it hasn't (and relies on other mechanisms to translate this string), the string will remain untranslated, and the "custom" translation mechanisms will be able to process it as before.

In any case, my guess is that localized programs already explicitly pass a localized help string to the `_VersionAction` constructor in order to circumvent the nonlocalized default help string:
```
parser.add_argument('-V', action='version', version='%(prog)s 3.9',
                    help=_("show program's version number and exit"))
```
These programs should also remain completely unaffected by this change.

Thanks!

Kind regards,
Jérémie.
History
Date User Action Args
2021-08-08 13:34:47jdetreysetrecipients: + jdetrey, bethard, thorsten, paul.j3, proski
2021-08-08 13:34:47jdetreysetmessageid: <1628429687.28.0.215712550073.issue16786@roundup.psfhosted.org>
2021-08-08 13:34:47jdetreylinkissue16786 messages
2021-08-08 13:34:46jdetreycreate