Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argparse uses %s in gettext calls #54737

Closed
merwok opened this issue Nov 25, 2010 · 9 comments
Closed

argparse uses %s in gettext calls #54737

merwok opened this issue Nov 25, 2010 · 9 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@merwok
Copy link
Member

merwok commented Nov 25, 2010

BPO 10528
Nosy @birkenfeld, @abalkin, @ericvsmith, @merwok
Dependencies
  • bpo-10497: Incorrect use of gettext in argparse
  • Files
  • fix-gettext-positionals.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/merwok'
    closed_at = <Date 2010-12-03.19:42:43.410>
    created_at = <Date 2010-11-25.12:25:37.066>
    labels = ['type-bug', 'library']
    title = 'argparse uses %s in gettext calls'
    updated_at = <Date 2010-12-03.19:42:43.409>
    user = 'https://github.com/merwok'

    bugs.python.org fields:

    activity = <Date 2010-12-03.19:42:43.409>
    actor = 'eric.araujo'
    assignee = 'eric.araujo'
    closed = True
    closed_date = <Date 2010-12-03.19:42:43.410>
    closer = 'eric.araujo'
    components = ['Library (Lib)']
    creation = <Date 2010-11-25.12:25:37.066>
    creator = 'eric.araujo'
    dependencies = ['10497']
    files = ['19920']
    hgrepos = []
    issue_num = 10528
    keywords = ['patch']
    message_count = 9.0
    messages = ['122357', '122406', '123124', '123129', '123173', '123211', '123213', '123234', '123285']
    nosy_count = 5.0
    nosy_names = ['georg.brandl', 'belopolsky', 'bethard', 'eric.smith', 'eric.araujo']
    pr_nums = []
    priority = 'high'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue10528'
    versions = ['Python 3.2']

    @merwok
    Copy link
    Member Author

    merwok commented Nov 25, 2010

    When you run xgettext other argparse.py, you get this warning:
    “'msgid' format string with unnamed arguments cannot be properly localized: The translator cannot reorder the arguments. Please consider using a format string with named arguments, and a mapping instead of a tuple for the arguments.”

    I don’t know if people already rely on strings from argparse, but for safety I think we should change them only in 3.2, if Steven agrees.

    (I have to check other stdlib modules.)

    @merwok merwok added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Nov 25, 2010
    @bethard
    Copy link
    Mannequin

    bethard mannequin commented Nov 25, 2010

    I think it's fine to fix this in 3.2 by switching to mappings where necessary.

    @merwok merwok self-assigned this Nov 26, 2010
    @merwok
    Copy link
    Member Author

    merwok commented Dec 2, 2010

    Georg, do I have to make a patch before beta1 for this to go in 3.2?

    @birkenfeld
    Copy link
    Member

    That would be good. While you could argue it's a bug, the fix is also slightly incompatible.

    @merwok
    Copy link
    Member Author

    merwok commented Dec 3, 2010

    The incompatibility worries me a bit. A program compatible with Python 3.1 and 3.2 would have to support both sets of messages; I don’t know whether the i18n tools support having all the strings in one PO file, and how inconvenient it would be for translators. I assume such transitions have happened in many projects and that people just accept the inconvenience.

    Attached patch changes the strings to avoid warnings. No tests added (I intend to write tests for i18n in argparse in the future, see bpo-10497 and bpo-10529).

    Steven, I’d like your +1 before committing anything. One message in particular is not very helpful, but I’ve been unable to find better placeholders (it’s in ArgumentPaser._get_value):
    msg = _('invalid %(name)s value: %(arg_string)r')

    @bethard
    Copy link
    Mannequin

    bethard mannequin commented Dec 3, 2010

    If I understand it right, before this patch, people couldn't really supply internationalizations for these calls - they would have had to have a translation for each possible value of, e.g. action.choices or parser.prefix_chars. So I think there's pretty minimal danger of breaking that code.

    Specific comments on names in the patch:

    • rename %(character) to %(prefix_chars)
    • rename %(name) to %(type) and %(arg_string) to %(value)
    • rename %(program_name) to %(prog)

    Basically, we should use the name of an Action or ArgumentParser attribute whenever it makes sense. Hopefully that will make it more intuitive what these mean when people are translating them.

    And yes, with the above changes, +1.

    @bethard
    Copy link
    Mannequin

    bethard mannequin commented Dec 3, 2010

    Hmm. I see I confused this with bpo-10529, where there really was a bug in the gettext calls. Nonetheless, +1 for switching from %s to %(xxx)s in 3.2 - since that's the first release in Python 3 that has argparse, I think it's really okay to do this.

    @merwok
    Copy link
    Member Author

    merwok commented Dec 3, 2010

    This bug is a warning, not a fatal error: “The translator cannot reorder the arguments.” Depending on the language, it may be a real pain.

    “Basically, we should use the name of an Action or ArgumentParser attribute whenever it makes sense. Hopefully that will make it more intuitive what these mean when people are translating them.” Exactly. That’s why I suggested %(program_name) instead of %(prog); keep in mind translators are not necessarily programmers, so the familiar argparse terms may not make sense to them.

    If Georg is okay with the lack of tests (apart manual testing showing that xgettext does not print warnings anymore), I will apply your changes and commit this tonight, which should be in time for beta1.

    @merwok
    Copy link
    Member Author

    merwok commented Dec 3, 2010

    Committed in r86993.

    @merwok merwok closed this as completed Dec 3, 2010
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants