[Fix] Fixed generation of .pot files
bzr revid: cbi@openerp.com-20120924134002-co53v0mbz8zicciv
This commit is contained in:
parent
a6fa3ac71b
commit
1d7b6d3e35
|
@ -163,15 +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")
|
||||
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(
|
||||
|
|
|
@ -443,10 +443,15 @@ def trans_export(lang, modules, buffer, format, cr):
|
|||
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':
|
||||
|
@ -487,17 +492,26 @@ def trans_export(lang, modules, buffer, format, cr):
|
|||
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 = []
|
||||
|
@ -506,9 +520,13 @@ def trans_parse_rml(de):
|
|||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue