def extract_messages_from_code(code, is_py=False): """Extracts translatable srings from a code file :param code: code from which translatable files are to be extracted :param is_py: include messages in triple quotes e.g. `_('''message''')`""" try: code = render_include(code) except TemplateError: # Exception will occur when it encounters John Resig's microtemplating code pass messages = [] messages += [(m.start(), m.groups()[0]) for m in re.compile('_\("([^"]*)"').finditer(code)] messages += [(m.start(), m.groups()[0]) for m in re.compile("_\('([^']*)'").finditer(code)] if is_py: messages += [ (m.start(), m.groups()[0]) for m in re.compile('_\("{3}([^"]*)"{3}.*\)').finditer(code) ] messages = [(pos, message) for pos, message in messages if is_translatable(message)] return pos_to_line_no(messages, code)
def extract_messages_from_code(code, is_py=False): try: code = render_include(code) except TemplateError: # Exception will occur when it encounters John Resig's microtemplating code pass messages = [] messages += re.findall('_\("([^"]*)"', code) messages += re.findall("_\('([^']*)'", code) if is_py: messages += re.findall('_\("{3}([^"]*)"{3}.*\)', code, re.S) return clean(messages)
def extract_messages_from_code(code, is_py=False): """Extracts translatable srings from a code file :param code: code from which translatable files are to be extracted :param is_py: include messages in triple quotes e.g. `_('''message''')`""" try: code = render_include(code) except TemplateError: # Exception will occur when it encounters John Resig's microtemplating code pass messages = [] messages += re.findall('_\("([^"]*)"', code) messages += re.findall("_\('([^']*)'", code) if is_py: messages += re.findall('_\("{3}([^"]*)"{3}.*\)', code, re.S) return clean(messages)
def extract_messages_from_code(code, is_py=False): """Extracts translatable srings from a code file :param code: code from which translatable files are to be extracted :param is_py: include messages in triple quotes e.g. `_('''message''')`""" try: code = render_include(code) except TemplateError: # Exception will occur when it encounters John Resig's microtemplating code pass messages = [] messages += [(m.start(), m.groups()[0]) for m in re.compile('_\("([^"]*)"').finditer(code)] messages += [(m.start(), m.groups()[0]) for m in re.compile("_\('([^']*)'").finditer(code)] if is_py: messages += [(m.start(), m.groups()[0]) for m in re.compile('_\("{3}([^"]*)"{3}.*\)').finditer(code)] messages = [(pos, message) for pos, message in messages if is_translatable(message)] return pos_to_line_no(messages, code)
def get_js(path): js = frappe.read_file(path) if js: return render_include(js)
def _add_code(self, path, fieldname): js = frappe.read_file(path) if js: self.set(fieldname, (self.get(fieldname) or "") + "\n\n" + render_include(js))