[yum-commits] test/misc-tests.py yum/i18n.py

zpavlas at osuosl.org zpavlas at osuosl.org
Thu Jan 9 15:08:27 UTC 2014


 test/misc-tests.py |   13 +++++++++++++
 yum/i18n.py        |    7 +++++++
 2 files changed, 20 insertions(+)

New commits:
commit e354fca0e2dad2fc38f8874488e308d660c148b7
Author: Zdenek Pavlas <zpavlas at redhat.com>
Date:   Tue Jan 7 16:31:03 2014 +0100

    fix "yum --help" with translated "Usage: %s\n". BZ 1033416

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..17267d6 100755
--- a/yum/i18n.py
+++ b/yum/i18n.py
@@ -500,6 +500,13 @@ 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._ = gettext.translation('messages', fallback=True).ugettext
 except:
     '''
     Something went wrong so we make a dummy _() wrapper there is just


More information about the Yum-commits mailing list