aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-03-20 19:59:25 +0100
committerÉric Araujo <merwok@netwok.org>2011-03-20 19:59:25 +0100
commit6a1454f3a441b6f84cabaff250b2744a5e4f4ec0 (patch)
treec0388134e7d07d6e5a88484a3eb6891bcd1ceaf3 /Lib/optparse.py
parenttabs are verboten. (diff)
downloadcpython-6a1454f3a441b6f84cabaff250b2744a5e4f4ec0.tar.gz
cpython-6a1454f3a441b6f84cabaff250b2744a5e4f4ec0.tar.bz2
cpython-6a1454f3a441b6f84cabaff250b2744a5e4f4ec0.zip
Use proper gettext plural forms in optparse (closes #4391).
Original patch by Dwayne Bailey.
Diffstat (limited to 'Lib/optparse.py')
-rw-r--r--Lib/optparse.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/Lib/optparse.py b/Lib/optparse.py
index 3eb652a6fe9..c2077136f05 100644
--- a/Lib/optparse.py
+++ b/Lib/optparse.py
@@ -86,10 +86,16 @@ def _repr(self):
# Id: errors.py 509 2006-04-20 00:58:24Z gward
try:
- from gettext import gettext
+ from gettext import gettext, ngettext
except ImportError:
def gettext(message):
return message
+
+ def ngettext(singular, plural, n):
+ if n == 1:
+ return singular
+ return plural
+
_ = gettext
@@ -1478,11 +1484,10 @@ class OptionParser (OptionContainer):
if option.takes_value():
nargs = option.nargs
if len(rargs) < nargs:
- if nargs == 1:
- self.error(_("%s option requires an argument") % opt)
- else:
- self.error(_("%s option requires %d arguments")
- % (opt, nargs))
+ self.error(ngettext(
+ "%(option)s option requires %(number)d argument",
+ "%(option)s option requires %(number)d arguments",
+ nargs) % {"option": opt, "number": nargs})
elif nargs == 1:
value = rargs.pop(0)
else:
@@ -1517,11 +1522,10 @@ class OptionParser (OptionContainer):
nargs = option.nargs
if len(rargs) < nargs:
- if nargs == 1:
- self.error(_("%s option requires an argument") % opt)
- else:
- self.error(_("%s option requires %d arguments")
- % (opt, nargs))
+ self.error(ngettext(
+ "%(option)s option requires %(number)d argument",
+ "%(option)s option requires %(number)d arguments",
+ nargs) % {"option": opt, "number": nargs})
elif nargs == 1:
value = rargs.pop(0)
else: