X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=npybabel.py;h=81cd6abf60ae6bee1fa1d78b0f5aa291818563c8;hb=0ae41592cd7c71a5add11af755a5e13f16744758;hp=0c79e5d7d1ef0336b74c9db6e73f5c744467c72e;hpb=be46b05129b13d70e30056973cdcc143e2728dc7;p=odoo%2Fodoo.git diff --git a/npybabel.py b/npybabel.py index 0c79e5d..81cd6ab 100755 --- a/npybabel.py +++ b/npybabel.py @@ -1,17 +1,35 @@ -#!/usr/bin/python +#!/usr/bin/env python # EASY-INSTALL-ENTRY-SCRIPT: 'Babel==0.9.6','console_scripts','pybabel' __requires__ = 'Babel==0.9.6' import sys from pkg_resources import load_entry_point import re +import json +import xml.etree.ElementTree as elt 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 *\( *((?:\".*?\")|(?:\'.*?\')) *\))""") - +XMLJS_EXPR = re.compile(r"""(?:\_t *\( *((?:"(?:[^"\\]|\\.)*")|(?:'(?:[^'\\]|\\.)*')) *\))""") + +def extract_xmljs(fileobj, keywords, comment_tags, options): + content = fileobj.read() + found = XMLJS_EXPR.finditer(content) + result = [] + index = 0 + line_nbr = 0 + for f in found: + mes = f.group(1) + mes = json.loads(mes) + while index < f.start(): + if content[index] == "\n": + line_nbr += 1 + index += 1 + result.append((line_nbr, None, mes, "")) + return result + def extract_qweb(fileobj, keywords, comment_tags, options): """Extract messages from XXX files. :param fileobj: the file-like object the messages should be extracted @@ -25,16 +43,23 @@ def extract_qweb(fileobj, keywords, comment_tags, options): tuples :rtype: ``iterator`` """ - content = fileobj.read() - found = QWEB_EXPR.finditer(content) result = [] - index = 0 - line_nbr = 0 - for f in found: - group = 1 if f.group(1) else 2 - while index < f.start(): - if content[index] == "\n": - line_nbr += 1 - index += 1 - result.append((line_nbr, None, f.group(group), "")) + def handle_text(str): + str = (str or "").strip() + if not str: + return + result.append((0, None, str, "")) + + def iter_elements(current_element): + for el in current_element: + if "t-js" not in el.attrib and \ + not ("t-jquery" in el.attrib and "t-operation" not in el.attrib) and \ + not ("t-translation" in el.attrib and el.attrib["t-translation"].strip() == "off"): + handle_text(el.text) + iter_elements(el) + handle_text(el.tail) + + tree = elt.parse(fileobj) + iter_elements(tree.getroot()) + return result