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
Comments
When you run xgettext other argparse.py, you get this warning: 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.) |
I think it's fine to fix this in 3.2 by switching to mappings where necessary. |
Georg, do I have to make a patch before beta1 for this to go in 3.2? |
That would be good. While you could argue it's a bug, the fix is also slightly incompatible. |
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): |
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:
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. |
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. |
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. |
Committed in r86993. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: