yifengyou / rpms / yum

Forked from rpms/yum 4 years ago
Clone

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

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