示例#1
0
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)
示例#2
0
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)
示例#3
0
文件: translate.py 项目: wacl/frappe
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)
示例#4
0
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)
示例#5
0
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)
示例#6
0
def get_js(path):
	js = frappe.read_file(path)
	if js:
		return render_include(js)
示例#7
0
	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))
示例#8
0
def get_js(path):
    js = frappe.read_file(path)
    if js:
        return render_include(js)