diff --git a/test/misc-tests.py b/test/misc-tests.py index 7d7d06f..11fd041 100644 --- a/test/misc-tests.py +++ b/test/misc-tests.py @@ -150,6 +150,19 @@ class MiscTests(DepsolveTests): self.assertEqual(type(actual), type(expected)) self.assertEqual(actual, expected) + def testOptparse(self): + # make 'Usage: %s\n' translated + import gettext + def dgettext(domain, msg, orig=gettext.dgettext): + if domain=='messages' and msg == 'Usage: %s\n': + return 'Pou\xc5\xbeit\xc3\xad: %s\n' + return orig(domain, msg) + gettext.dgettext = dgettext + # run "yum --help" + from optparse import OptionParser + parser = OptionParser(usage=u'\u011b\u0161\u010d') + self.assertRaises(SystemExit, parser.parse_args, args=['--help']) + def setup_logging(): logging.basicConfig() plainformatter = logging.Formatter("%(message)s") diff --git a/yum/i18n.py b/yum/i18n.py index 76a258d..2c0cbce 100755 --- a/yum/i18n.py +++ b/yum/i18n.py @@ -500,6 +500,14 @@ try: t = gettext.translation('yum', fallback=True) _ = t.ugettext P_ = t.ungettext + + # we describe yum commands and options with unicode but optparse + # mixes this with non-unicode translations so "yum --help" may fail. + # It's much easier to fix this in optparse than in yum. BZ 1033416 + import optparse + if optparse._ is gettext.gettext: + #optparse._ = lambda msg: to_unicode(gettext.gettext(msg)) + optparse._ = gettext.translation('messages', fallback=True).ugettext except: ''' Something went wrong so we make a dummy _() wrapper there is just