# * (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(
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 = []