[gimp-help-2] [xml2po] Fix decode error



commit bec7d866b8c762440372242bdd906646a85275ef
Author: Ulf-D. Ehlert <ulfehlert svn gnome org>
Date:   Thu Jul 30 11:34:34 2009 +0200

    [xml2po] Fix decode error
    
    Prevent xml2po from raising an Error if a translated attribute
    contains non-ASCII characters.

 tools/xml2po |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/tools/xml2po b/tools/xml2po
index 220f8ba..6235f25 100755
--- a/tools/xml2po
+++ b/tools/xml2po
@@ -456,7 +456,7 @@ def processAttribute(node, attr):
     assert node and attr
     outtxt = attr.content
     if mode=='merge':
-        translation = getTranslation(outtxt, 0)  # may be None
+        translation = getTranslation(outtxt, 0)  # unicode or None
         if translation:
             replaceAttributeContentsWithText(attr, translation.encode('utf-8'))
     else:
@@ -510,7 +510,11 @@ def processElementTag(node, replacements, restart = 0):
         if restart or worth:
             i = 0
             while i < len(myrepl):
-                replacement = '<%s>%s</%s>' % (myrepl[i][0], myrepl[i][3], myrepl[i][2])
+                # myrepl[i][0] may contain translated attributes with
+                # non-ASCII chars, so implicit conversion to <str> may fail
+                replacement = '<%s>%s</%s>' % (myrepl[i][0].decode('utf-8'),
+                                               myrepl[i][3],
+                                               myrepl[i][2])
                 i += 1
                 translation = translation.replace('<placeholder-%d/>' % (i), replacement)
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]