[yum-git] yum/i18n.py
Tim Lauridsen
timlau at linux.duke.edu
Thu Feb 7 09:59:59 UTC 2008
yum/i18n.py | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
New commits:
commit e4bdf577f5e197b98daff45b55f061f8b639162d
Author: Tim Lauridsen <timlau at fedoraproject.org>
Date: Thu Feb 7 10:44:21 2008 +0100
Make the _() translation wrapper make sure that the translated string is Unicode, to solve problem with ISO-8859-1 translation files
diff --git a/yum/i18n.py b/yum/i18n.py
index 14e16dd..dddf34e 100644
--- a/yum/i18n.py
+++ b/yum/i18n.py
@@ -10,17 +10,40 @@ $Id$
__version__ = "$Revision$"[11:-2]
__date__ = "$Date$"[7:-2]
+import types
+
+def _toUTF( txt ):
+ """ this function convert a string to unicode"""
+ rc=""
+ if isinstance(txt,types.UnicodeType):
+ return txt
+ else:
+ try:
+ rc = unicode( txt, 'utf-8' )
+ except UnicodeDecodeError, e:
+ rc = unicode( txt, 'iso-8859-1' )
+ return rc
+
+_transfn = None
+
+def _translate(txt):
+ txt = _transfn(txt)
+ return _toUTF(txt)
+
+
+
try:
import gettext
import sys
if sys.version_info[0] == 2:
t = gettext.translation('yum')
- _ = t.gettext
+ _transfn = t.gettext
else:
gettext.bindtextdomain('yum', '/usr/share/locale')
gettext.textdomain('yum')
- _ = gettext.gettext
-
+ _transfn = gettext.gettext
+ _ = _translate
+
except:
def _(str):
"""pass given string as-is"""
More information about the Yum-cvs-commits
mailing list