[issue8841] GetoptError strings should be localized
Filip Gruszczyński grusz...@gmail.com added the comment: Here is a small patch. Could you advise me, how can I test it now? Or is it an issue, that doesn't require writing new tests? -- keywords: +patch Added file: http://bugs.python.org/file20970/8841.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8841 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8841] GetoptError strings should be localized
Filip Gruszczyński grusz...@gmail.com added the comment: I'd be happy to provide a patch. How about extending getopt api to something like this: optlist, args = getopt.getopt(['-b'], 'e', not_recognized=no %s option, mate!) GetoptError: no -b option, mate! Or maybe you should provide a dictionary? optlist, args = getopt.getopt(['-b'], 'e', errors={'not_recognized': no %s option, mate!) GetoptError: no -b option, mate! I have little experience with making design decisions, so if someone could guide me here, I will get down and provide a patch with proposed solution. -- nosy: +gruszczy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8841 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8841] GetoptError strings should be localized
Filip Gruszczyński grusz...@gmail.com added the comment: One more solution. Maybe getopt should expose variables that hold error messages (rather than have them hardcoded in the code), that can be simply substituted by the user before he runs getopt? But I don't really like this one. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8841 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8841] GetoptError strings should be localized
Éric Araujo mer...@netwok.org added the comment: Filip: The standard way of doing localization is thanks to the gettext module. Richard: Regarding the contents of the error messages, please make specific remarks on what is lacking. -- stage: - needs patch versions: +Python 3.3 -Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8841 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8841] GetoptError strings should be localized
Filip Gruszczyński grusz...@gmail.com added the comment: I understand I should do something similar to what is done in argparse: from gettext import gettext as _, ngettext ... message = ngettext('conflicting option string: %s', 'conflicting option strings: %s', len(conflicting_actions)) and then let user define those messages somewhere in his own po files? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8841 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8841] GetoptError strings should be localized
Richard Lowe richl...@richlowe.net added the comment: I don't find anything lacking about the error messages, I meant that there were no more specific exceptions, or fields in GetoptError to allow the caller to tell what was specifically wrong and provide its own localized messages. So while the defaults are unlocalized, all an application can do is interpret the error string to provide a localized message. The solution I was thinking of is getopt raising sub-types of GetoptError for each specific error case (unknown option, option requires argument, etc), and the message text of each of those being localized through gettext(). I'm not sure what problems that could cause with compatibility however, beyond obviously anyone who's already resorted to interpreting the string would have problems. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8841 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8841] GetoptError strings should be localized
Éric Araujo mer...@netwok.org added the comment: Richard: It’s not common to use subclasses to allow message customization. Would gettext cover your need? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8841 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8841] GetoptError strings should be localized
Richard Lowe richl...@richlowe.net added the comment: Sure, just localizing them in the getopt implementation would be fine. I suggested subclassing to solve the more general problem of the caller being able to tell one getopt error from another, for which it is a pretty common solution. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8841 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8841] GetoptError strings should be localized
Éric Araujo mer...@netwok.org added the comment: Do you want to provide a patch? -- nosy: +eric.araujo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8841 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8841] GetoptError strings should be localized
Changes by Terry J. Reedy tjre...@udel.edu: -- versions: +Python 3.2 -Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8841 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8841] GetoptError strings should be localized
New submission from Richard Lowe richl...@richlowe.net: The GetoptError exception raised by getopt.getopt() to indicate errors in provided arguments seems intended to be displayed to the user[1], but is not localized and doesn't contain enough information, short of interpreting the error string, for consumers to raise their own, localized, error. [1] http://docs.python.org/library/getopt.html -- components: Library (Lib) messages: 106632 nosy: richlowe priority: normal severity: normal status: open title: GetoptError strings should be localized type: feature request versions: Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8841 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com