[imp] improved wqweb scanning for translations

bzr revid: nicolas.vanhoren@openerp.com-20110816113400-f1laiorv1nx58yo9
This commit is contained in:
niv-openerp 2011-08-16 13:34:00 +02:00
parent be46b05129
commit f713807311
1 changed files with 10 additions and 4 deletions

View File

@ -4,14 +4,17 @@ __requires__ = 'Babel==0.9.6'
import sys
from pkg_resources import load_entry_point
import re
import json
if __name__ == '__main__':
sys.exit(
load_entry_point('Babel==0.9.6', 'console_scripts', 'pybabel')()
)
QWEB_EXPR = re.compile(r"""(?:\< *t\-tr *\>(.*?)\< *\/t\-tr *\>)|(?:\_t *\( *((?:\".*?\")|(?:\'.*?\')) *\))""")
QWEB_EXPR = re.compile(r"""(?:\< *t\-tr *\>(.*?)\< *\/t\-tr *\>)|(?:\_t *\( *((?:"(?:[^"\\]|\\.)*")|(?:'(?:[^'\\]|\\.)*')) *\))""")
XML_GROUP = 1
JS_GROUP = 2
def extract_qweb(fileobj, keywords, comment_tags, options):
"""Extract messages from XXX files.
:param fileobj: the file-like object the messages should be extracted
@ -31,10 +34,13 @@ def extract_qweb(fileobj, keywords, comment_tags, options):
index = 0
line_nbr = 0
for f in found:
group = 1 if f.group(1) else 2
group = XML_GROUP if f.group(XML_GROUP) else JS_GROUP
mes = f.group(group)
if group == JS_GROUP:
mes = json.loads(mes)
while index < f.start():
if content[index] == "\n":
line_nbr += 1
index += 1
result.append((line_nbr, None, f.group(group), ""))
result.append((line_nbr, None, mes, ""))
return result