[MERGE] OPW 577045: translate: properly export and translate terms in XSL-based reports
authorOlivier Dony <odo@openerp.com>
Mon, 8 Oct 2012 11:09:46 +0000 (13:09 +0200)
committerOlivier Dony <odo@openerp.com>
Mon, 8 Oct 2012 11:09:46 +0000 (13:09 +0200)
This patch comes with a related patch on addons which
fixes a lot of cases of terms that were not properly
translated in reports, due to improper use of the
translation system. The addons patch also adds a
lot of missing entries in the POT files.

bzr revid: odo@openerp.com-20121008110946-21984tjvhoy8zkx9

1  2 
openerp/report/interface.py
openerp/tools/translate.py

@@@ -163,15 -163,30 +163,30 @@@ class report_rml(report_int)
          # * (re)build/update the stylesheet with the translated items
  
          def translate(doc, lang):
-             for node in doc.xpath('//*[@t]'):
-                 if not node.text:
-                     continue
-                 translation = ir_translation_obj._get_source(cr, uid, self.name2, 'xsl', lang, node.text)
-                 if translation:
-                     node.text = translation
+             translate_aux(doc, lang, False)
 -            
++
+         def translate_aux(doc, lang, t):
+             for node in doc:
 -                t = t or node.get("t")  
++                t = t or node.get("t")
+                 if t:
+                     text = None
+                     tail = None
+                     if node.text:
 -                        text = node.text.strip().replace('\n',' ')    
++                        text = node.text.strip().replace('\n',' ')
+                     if node.tail:
+                         tail = node.tail.strip().replace('\n',' ')
+                     if text:
+                         translation1 = ir_translation_obj._get_source(cr, uid, self.name2, 'xsl', lang, text)
+                         if translation1:
+                             node.text = node.text.replace(text, translation1)
+                     if tail:
+                         translation2 = ir_translation_obj._get_source(cr, uid, self.name2, 'xsl', lang, tail)
+                         if translation2:
+                             node.tail = node.tail.replace(tail, translation2)
 -                translate_aux(node, lang, t)  
 -             
++                translate_aux(node, lang, t)
 +
          if context.get('lang', False):
-             translate(stylesheet, context['lang'])
+             translate(stylesheet.iter(), context['lang'])
  
          transform = etree.XSLT(stylesheet)
          xml = etree.tostring(
@@@ -487,17 -492,26 +492,26 @@@ def trans_export(lang, modules, buffer
      del trans
  
  def trans_parse_xsl(de):
+     return list(set(trans_parse_xsl_aux(de, False)))
 -def trans_parse_xsl_aux(de, t):   
++def trans_parse_xsl_aux(de, t):
      res = []
 -   
++
      for n in de:
-         if n.get("t"):
-             for m in n:
-                 if isinstance(m, SKIPPED_ELEMENT_TYPES) or not m.text:
+         t = t or n.get("t")
+         if t:
+                 if isinstance(n, SKIPPED_ELEMENT_TYPES) or n.tag.startswith('{http://www.w3.org/1999/XSL/Transform}'):
                      continue
-                 l = m.text.strip().replace('\n',' ')
-                 if len(l):
-                     res.append(l.encode("utf8"))
-         res.extend(trans_parse_xsl(n))
+                 if n.text:
+                     l = n.text.strip().replace('\n',' ')
+                     if len(l):
+                         res.append(l.encode("utf8"))
+                 if n.tail:
+                     l = n.tail.strip().replace('\n',' ')
+                     if len(l):
+                         res.append(l.encode("utf8"))
+         res.extend(trans_parse_xsl_aux(n, t))
 -    return res   
 +    return res
  
  def trans_parse_rml(de):
      res = []