classification
Title: argparse: the word 'default' (in help) is not marked as translatable
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: paul.j3, woutgg, xtreak
Priority: normal Keywords: patch

Created on 2018-06-05 22:12 by woutgg, last changed 2019-04-07 02:53 by eamanu.

Pull Requests
URL Status Linked Edit
PR 12711 open eamanu, 2019-04-07 02:53
Messages (5)
msg318784 - (view) Author: woutgg (woutgg) Date: 2018-06-05 22:12
The word 'default', used to indicate default arguments in the help text (found here: Lib/argparse.py:681) is missing the gettext wrapper, causing it to be untranslatable.
msg318787 - (view) Author: woutgg (woutgg) Date: 2018-06-05 22:28
Note: the line number in the link is not correct anymore, I'm not sure how to link to a specific commit so here is the source line: `help += ' (default: %(default)s)'`.
msg339543 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-04-06 19:55
@paul.j3 I assume this is an easy issue of wrapping "default" with _() at [0]. There doesn't seem to be any tests for localization in argparse.

https://github.com/python/cpython/blob/2ea8099523581cf2ecc060831a53debb57ff98ee/Lib/argparse.py#L682
msg339547 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2019-04-06 21:35
I haven't paid much attention to the localization issues in `argparse`.  

The issue is with the help modification done by the:

class ArgumentDefaultsHelpFormatter

    help += ' (default: %(default)s)'

This formatter is a convenience, not something critical.  The programmer could always include that 'default' string in the help line with their preferred terminology.  They don't have to use this formatter to show the default values in their help lines.

_() is used mostly for error messages with the format 

    msg = _('message %(value)s')
    raise Error( msg % args)

So the following change might work:

    help += _(' (default: %(default)s)')

But I'm not in a position to test it or evaluate its usefulness.
msg339549 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2019-04-06 21:40
https://bugs.python.org/issue16786

points out that the 'version' action isn't localizable either.
History
Date User Action Args
2019-04-07 02:53:53eamanusetkeywords: + patch
stage: patch review
pull_requests: + pull_request12636
2019-04-06 21:40:03paul.j3setmessages: + msg339549
2019-04-06 21:35:44paul.j3setmessages: + msg339547
2019-04-06 19:55:12xtreaksetversions: + Python 3.8
nosy: + paul.j3, xtreak

messages: + msg339543

components: + Library (Lib)
2018-06-05 22:28:32woutggsetmessages: + msg318787
2018-06-05 22:12:35woutggcreate