From 741edc3d373ba3775b2f87d79beae2891771ce44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Detrey?= Date: Sun, 8 Aug 2021 16:15:16 +0200 Subject: [PATCH 1/3] bpo-44865: Missing translations in argparse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A couple of other missing translations are addressed by #12711. Incidentally, this also fixes a bug with the "(default: …)" help string of the `BooleanOptionalAction` class: when used with the `ArgumentDefaultsHelpFormatter`, a second "(default: …)" string would be added to the help text. This was due to the fact that the `default` value was immediately expanded in the help string, and thus wasn't detected as a "(default: …)" string by the `ArgumentDefaultsHelpFormatter._get_help_string()` method (which relies on finding a named format argument `%(default)` inside the help string). --- Lib/argparse.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/argparse.py b/Lib/argparse.py index 33c5d705bc62d2..d18f1d8f7cf44d 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -222,7 +222,8 @@ def format_help(self): # add the heading if the section was non-empty if self.heading is not SUPPRESS and self.heading is not None: current_indent = self.formatter._current_indent - heading = '%*s%s:\n' % (current_indent, '', self.heading) + heading_text = _('%(heading)s:') % dict(heading=self.heading) + heading = '%*s%s\n' % (current_indent, '', heading_text) else: heading = '' @@ -748,7 +749,7 @@ def __str__(self): if self.argument_name is None: format = '%(message)s' else: - format = 'argument %(argument_name)s: %(message)s' + format = _('argument %(argument_name)s: %(message)s') return format % dict(message=self.message, argument_name=self.argument_name) @@ -876,7 +877,7 @@ def __init__(self, _option_strings.append(option_string) if help is not None and default is not None: - help += f" (default: {default})" + help += _(' (default: %(default)s)') super().__init__( option_strings=_option_strings, From 6e7a27723e544e651cc4c8186d83d5759f15d1d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Detrey?= Date: Tue, 24 Aug 2021 20:48:21 +0200 Subject: [PATCH 2/3] bpo-44865: Add NEWS entry --- .../NEWS.d/next/Library/2021-08-24-20-47-37.bpo-44865.c3BhZS.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2021-08-24-20-47-37.bpo-44865.c3BhZS.rst diff --git a/Misc/NEWS.d/next/Library/2021-08-24-20-47-37.bpo-44865.c3BhZS.rst b/Misc/NEWS.d/next/Library/2021-08-24-20-47-37.bpo-44865.c3BhZS.rst new file mode 100644 index 00000000000000..56fb5cb7cf4584 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-08-24-20-47-37.bpo-44865.c3BhZS.rst @@ -0,0 +1 @@ +Add missing calls to localization function in :mod:`argparse`. From 55c82f42de3dcb32d214b8c953f55745e197268d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Detrey?= Date: Mon, 26 Feb 2024 21:13:38 +0100 Subject: [PATCH 3/3] bpo-44865: Update NEWS entry --- .../next/Library/2021-08-24-20-47-37.bpo-44865.c3BhZS.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2021-08-24-20-47-37.bpo-44865.c3BhZS.rst b/Misc/NEWS.d/next/Library/2021-08-24-20-47-37.bpo-44865.c3BhZS.rst index 56fb5cb7cf4584..ecdb26cdd6edd6 100644 --- a/Misc/NEWS.d/next/Library/2021-08-24-20-47-37.bpo-44865.c3BhZS.rst +++ b/Misc/NEWS.d/next/Library/2021-08-24-20-47-37.bpo-44865.c3BhZS.rst @@ -1 +1 @@ -Add missing calls to localization function in :mod:`argparse`. +Add missing call to localization function in :mod:`argparse`.