REPORT: fix rml translation, translate before eval
authorced <>
Tue, 20 Feb 2007 13:41:01 +0000 (13:41 +0000)
committerced <>
Tue, 20 Feb 2007 13:41:01 +0000 (13:41 +0000)
bzr revid: ced-4608d23f742cf83ca3cf7e7d2101eea27d79caeb

bin/report/report_sxw.py

index 1ba0d78..e36cebf 100644 (file)
@@ -167,20 +167,6 @@ class rml_parse(object):
        def _parse_text(self, text, level=[]):
                res = self._regex.findall(text)
                todo = []
-               for key in res:
-                       newtext = self._eval(key)
-                       for i in range(len(level)):
-                               if isinstance(newtext, list):
-                                       newtext = newtext[level[i]]
-                       if isinstance(newtext, list):
-                               todo.append((key, newtext))
-                       else:
-                               if not isinstance(newtext, basestring):
-                                       newtext = str(newtext)
-                               # if there are two [[]] blocks the same, it will replace both
-                               # but it's ok because it should evaluate to the same thing 
-                               # anyway
-                               text = text.replace('[['+key+']]', newtext.decode('utf8'))
                # translate the text
                # the "split [[]] if not match [[]]" is not very nice, but I 
                # don't see how I could do it better...
@@ -200,6 +186,20 @@ class rml_parse(object):
                                                        if translated_string:
                                                                piece_list[pn] = piece_list[pn].replace(source_string, translated_string.decode('utf8'))
                                text = ''.join(piece_list)
+               for key in res:
+                       newtext = self._eval(key)
+                       for i in range(len(level)):
+                               if isinstance(newtext, list):
+                                       newtext = newtext[level[i]]
+                       if isinstance(newtext, list):
+                               todo.append((key, newtext))
+                       else:
+                               if not isinstance(newtext, basestring):
+                                       newtext = str(newtext)
+                               # if there are two [[]] blocks the same, it will replace both
+                               # but it's ok because it should evaluate to the same thing 
+                               # anyway
+                               text = text.replace('[['+key+']]', newtext.decode('utf8'))
                self._node.data = text
                if len(todo):
                        for key, newtext in todo: