From f713807311f84d2534bba1084b9839363f466dc3 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 16 Aug 2011 13:34:00 +0200 Subject: [PATCH] [imp] improved wqweb scanning for translations bzr revid: nicolas.vanhoren@openerp.com-20110816113400-f1laiorv1nx58yo9 --- npybabel.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/npybabel.py b/npybabel.py index 0c79e5d7d1e..3d9deaec676 100755 --- a/npybabel.py +++ b/npybabel.py @@ -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