Blame SOURCES/BZ-1033416-yum-error-on-non-us-locale.patch

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