# * (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")
+ if t:
+ text = None
+ tail = None
+ if node.text:
+ 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)
+
if context.get('lang', False):
- translate(stylesheet, context['lang'])
+ translate(stylesheet.iter(), context['lang'])
transform = etree.XSLT(stylesheet)
xml = etree.tostring(
row = grouped_rows.setdefault(src, {})
row.setdefault('modules', set()).add(module)
if ('translation' not in row) or (not row['translation']):
- row['translation'] = trad
+ if trad != src:
+ row['translation'] = trad
row.setdefault('tnrs', []).append((type, name, res_id))
for src, row in grouped_rows.items():
+ if newlang:
+ row['translation'] = ''
+ elif not row.get('translation'):
+ row['translation'] = src
writer.write(row['modules'], row['tnrs'], src, row['translation'])
elif format == 'tgz':
del trans
def trans_parse_xsl(de):
+ return list(set(trans_parse_xsl_aux(de, False)))
+
+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))
- return res
+ 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
def trans_parse_rml(de):
res = []
if isinstance(m, SKIPPED_ELEMENT_TYPES) or not m.text:
continue
string_list = [s.replace('\n', ' ').strip() for s in re.split('\[\[.+?\]\]', m.text)]
+ string_list2 = [s.replace('\n', ' ').replace('translate(', '')[:-1].strip('"\'') for s in re.findall('translate\(.+?\)', m.text)]
for s in string_list:
if s:
res.append(s.encode("utf8"))
+ for s in string_list2:
+ if s:
+ res.append(s.encode("utf8"))
res.extend(trans_parse_rml(n))
return res