forked from NaN-tic/trytond-jasper_reports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
translation.py
50 lines (40 loc) · 1.63 KB
/
translation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# This file is part jasper_reports module for Tryton.
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
import re
from xml import dom
from trytond.transaction import Transaction
from trytond.pool import Pool, PoolMeta
__all__ = [
'ReportTranslationSet',
'TranslationClean',
]
class ReportTranslationSet(metaclass=PoolMeta):
__name__ = "ir.translation.set"
def _translate_jasper_report(self, node):
strings = []
if node.nodeType in (node.CDATA_SECTION_NODE, node.TEXT_NODE):
if not (node.parentNode and
node.parentNode.tagName.endswith('Expression')):
return []
if node.nodeValue:
node_strings = re.findall(r'tr *\([^\(]*,[ ]*"([^"]*)"\)',
node.nodeValue)
strings += [x for x in node_strings if x]
for child in [x for x in node.childNodes]:
strings.extend(self._translate_jasper_report(child))
return strings
def extract_report_jrxml(self, content):
document = dom.minidom.parseString(content)
return self._translate_jasper_report(document)
class TranslationClean(metaclass=PoolMeta):
__name__ = 'ir.translation.clean'
@staticmethod
def _clean_jasper(translation):
Report = Pool().get('ir.action.report')
with Transaction().set_context(active_test=False):
# TODO: Clean strings that no more exists in the report?
if not Report.search([
('report_name', '=', translation.name),
]):
return True