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

Incorrect use of gettext in argparse #54706

Closed
merwok opened this issue Nov 22, 2010 · 8 comments
Closed

Incorrect use of gettext in argparse #54706

merwok opened this issue Nov 22, 2010 · 8 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 22, 2010

BPO 10497
Nosy @abalkin, @merwok
Files
  • gettext-argparse.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:26:08.157>
    created_at = <Date 2010-11-22.02:31:24.784>
    labels = ['type-bug', 'library']
    title = 'Incorrect use of gettext in argparse'
    updated_at = <Date 2010-12-03.19:26:08.156>
    user = 'https://github.com/merwok'

    bugs.python.org fields:

    activity = <Date 2010-12-03.19:26:08.156>
    actor = 'eric.araujo'
    assignee = 'eric.araujo'
    closed = True
    closed_date = <Date 2010-12-03.19:26:08.157>
    closer = 'eric.araujo'
    components = ['Library (Lib)']
    creation = <Date 2010-11-22.02:31:24.784>
    creator = 'eric.araujo'
    dependencies = []
    files = ['19766']
    hgrepos = []
    issue_num = 10497
    keywords = ['patch']
    message_count = 8.0
    messages = ['122068', '122076', '122301', '122355', '123177', '123214', '123233', '123282']
    nosy_count = 3.0
    nosy_names = ['belopolsky', 'bethard', 'eric.araujo']
    pr_nums = []
    priority = 'high'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue10497'
    versions = ['Python 2.7', 'Python 3.2']

    @merwok
    Copy link
    Member Author

    merwok commented Nov 22, 2010

    I found two calls to gettext that are incorrect. See attached patch.

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

    abalkin commented Nov 22, 2010

    The patch makes sense. I wonder if i10n of programs using argparse should be mentioned in docs. Providing a sample translation file somewhere may not be a bad idea at least for testing.

    @bethard
    Copy link
    Mannequin

    bethard mannequin commented Nov 24, 2010

    Looks like a great fix.

    And yes, anyone who knows anything about gettext, please feel free to add a test or ten. ;-) I just copied optparse when I put that stuff in, so I have no confidence in how it's done now.

    @merwok
    Copy link
    Member Author

    merwok commented Nov 25, 2010

    A bit of rationale behind the patch. You probably know that the gettext/_ functions serves two roles: Identifying the strings to translate, and retrieving the translation from a catalog.

    At strings extraction time, the string in the line
    msg = _('unknown parser %r (choices: %s)' % tup)
    will be found by xgettext (just checked), so the .pot and .po files will include it. So far, so good.

    At runtime however, the gettext function will get "unknown parser 'parserr' (choices: ('some', 'tuple'))" as argument, which isn’t in the translation catalogs. Doing the string interpolation after the gettext call (my patch) avoids this problem.

    I will write a test for those two strings.

    @merwok
    Copy link
    Member Author

    merwok commented Dec 3, 2010

    I’ve started on a test but I’m not sure how to proceed, since I need to use or intercept gettext and compare the error messages of argparse with translated messages to prove that the gettext calls are bogus. There are various ways of using or intercepting gettext from tests, but I have to experiment a bit before I can propose the simplest patch that could possibly work.

    Exceptionally, I’d like to commit the change as is, and defer the testing for some months, until I can get to bpo-10529.

    @merwok merwok self-assigned this Dec 3, 2010
    @bethard
    Copy link
    Mannequin

    bethard mannequin commented Dec 3, 2010

    Yes, I think it's okay to fix this without a test, given that it's a nontrivial amount of work to test gettext stuff. I'd rather have it working now, without tests, than wait until we know how to test stuff with gettext.

    It's also a pretty minor, obvious fix. Of course, I assume you'll make sure this also merges correctly with your bpo-10528 patch.

    @merwok
    Copy link
    Member Author

    merwok commented Dec 3, 2010

    From the other bug: “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.” Exactly.

    I will commit this evening and refresh the other patch (there is one overlapping change).

    @merwok
    Copy link
    Member Author

    merwok commented Dec 3, 2010

    Fixed in r86984 (py3k) and r86990 (2.7).

    @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