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



commit 9ca6dc99f69158e107b442e43fc0f008d3952acb
Author: Ulf-D. Ehlert <ulfehlert svn gnome org>
Date:   Wed Dec 16 21:19:38 2009 +0100

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

 tools/xml2po/__init__.py |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/tools/xml2po/__init__.py b/tools/xml2po/__init__.py
index 8d935d6..424c6ee 100644
--- a/tools/xml2po/__init__.py
+++ b/tools/xml2po/__init__.py
@@ -420,7 +420,7 @@ class XMLDocument(object):
 
         outtxt = self.normalizeString(attr.content)
         if self.app.operation == 'merge':
-            translation = self.app.getTranslation(outtxt)  # may be None
+            translation = self.app.getTranslation(outtxt)  # unicode or None
             if translation is not None:
                 self.replaceAttributeContentsWithText(attr,
                                                       translation.encode('utf-8'))
@@ -477,7 +477,10 @@ class XMLDocument(object):
 
         if restart or worth:
             for i, repl in enumerate(myrepl):
-                replacement = '<%s>%s</%s>' % (repl[0], repl[3], repl[2])
+                # repl[0] may contain translated attributes with
+                # non-ASCII chars, so implicit conversion to <str> may fail
+                replacement = '<%s>%s</%s>' % \
+                              (repl[0].decode('utf-8'), repl[3], repl[2])
                 translation = translation.replace('<placeholder-%d/>' % (i+1), replacement)
 
             if worth:



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