[Usability] Now tells the user in the error message which account triggers the error
[odoo/odoo.git] / npybabel.py
1 #!/usr/bin/env python
2 # EASY-INSTALL-ENTRY-SCRIPT: 'Babel==0.9.6','console_scripts','pybabel'
3 __requires__ = 'Babel==0.9.6'
4 import sys
5 from pkg_resources import load_entry_point
6 import re
7 import json
8 import xml.etree.ElementTree as elt
9
10 if __name__ == '__main__':
11     sys.exit(
12         load_entry_point('Babel==0.9.6', 'console_scripts', 'pybabel')()
13     )
14     
15 XMLJS_EXPR = re.compile(r"""(?:\_t *\( *((?:"(?:[^"\\]|\\.)*")|(?:'(?:[^'\\]|\\.)*')) *\))""")
16
17 def extract_xmljs(fileobj, keywords, comment_tags, options):
18     content = fileobj.read()
19     found = XMLJS_EXPR.finditer(content)
20     result = []
21     index = 0
22     line_nbr = 0
23     for f in found:
24         mes = f.group(1)
25         mes = json.loads(mes)
26         while index < f.start():
27             if content[index] == "\n":
28                 line_nbr += 1
29             index += 1
30         result.append((line_nbr, None, mes, ""))
31     return result
32
33 def extract_qweb(fileobj, keywords, comment_tags, options):
34     """Extract messages from XXX files.
35     :param fileobj: the file-like object the messages should be extracted
36                     from
37     :param keywords: a list of keywords (i.e. function names) that should
38                      be recognized as translation functions
39     :param comment_tags: a list of translator tags to search for and
40                          include in the results
41     :param options: a dictionary of additional options (optional)
42     :return: an iterator over ``(lineno, funcname, message, comments)``
43              tuples
44     :rtype: ``iterator``
45     """
46     result = []
47     def handle_text(str):
48         str = (str or "").strip()
49         if not str:
50             return
51         result.append((0, None, str, ""))
52     
53     def iter_elements(current_element):
54         for el in current_element:
55             if "t-js" not in el.attrib and \
56                     not ("t-jquery" in el.attrib and "t-operation" not in el.attrib) and \
57                     not ("t-translation" in el.attrib and el.attrib["t-translation"].strip() == "off"):
58                 handle_text(el.text)
59                 iter_elements(el)
60             handle_text(el.tail)
61     
62     tree = elt.parse(fileobj)
63     iter_elements(tree.getroot())
64
65     return result