+ yield (line_nbr, None, msg, [TRANSLATION_FLAG_COMMENT])
+
+def extract_qweb(fileobj, keywords, comment_tags, options):
+ """Extract messages from qweb template files.
+ :param fileobj: the file-like object the messages should be extracted
+ from
+ :param keywords: a list of keywords (i.e. function names) that should
+ be recognized as translation functions
+ :param comment_tags: a list of translator tags to search for and
+ include in the results
+ :param options: a dictionary of additional options (optional)
+ :return: an iterator over ``(lineno, funcname, message, comments)``
+ tuples
+ :rtype: ``iterator``
+ """
+ result = []
+ def handle_text(text, lineno):
+ text = (text or "").strip()
+ if len(text) > 1: # Avoid mono-char tokens like ':' ',' etc.
+ result.append((lineno, None, text, [TRANSLATION_FLAG_COMMENT]))
+
+ # not using elementTree.iterparse because we need to skip sub-trees in case
+ # the ancestor element had a reason to be skipped
+ def iter_elements(current_element):
+ for el in current_element:
+ if isinstance(el, SKIPPED_ELEMENT_TYPES): continue
+ 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, el.sourceline)
+ for att in ('title', 'alt', 'label', 'placeholder'):
+ if att in el.attrib:
+ handle_text(el.attrib[att], el.sourceline)
+ iter_elements(el)
+ handle_text(el.tail, el.sourceline)
+
+ tree = elt.parse(fileobj)
+ iter_elements(tree.getroot())
+