|
@@ -23,6 +23,35 @@ from frappe.utils import get_bench_path, is_html, strip, strip_html_tags |
|
|
from frappe.query_builder import Field, DocType |
|
|
from frappe.query_builder import Field, DocType |
|
|
from pypika.terms import PseudoColumn |
|
|
from pypika.terms import PseudoColumn |
|
|
|
|
|
|
|
|
|
|
|
TRANSLATE_PATTERN = re.compile( |
|
|
|
|
|
r"_\(" # starts with literal `_(` work with both python / JS |
|
|
|
|
|
|
|
|
|
|
|
# BEGIN: message search |
|
|
|
|
|
r"([\"']{,3})" # start of message string identifier - allows: ', ", """, '''; 1st capture group |
|
|
|
|
|
r"(?P<message>((?!\1).)*)" # Keep matching until string closing identifier is met which is same as 1st capture group |
|
|
|
|
|
r"\1" # match exact string closing identifier |
|
|
|
|
|
# END: message search |
|
|
|
|
|
|
|
|
|
|
|
# BEGIN: python context search |
|
|
|
|
|
r"(\s*,\s*context\s*=\s*" # capture `context=` with ignoring whitespace |
|
|
|
|
|
r"([\"'])" # start of context string identifier; 5th capture group |
|
|
|
|
|
r"(?P<py_context>((?!\5).)*)" # capture context string till closing id is found |
|
|
|
|
|
r"\5" # match context string closure |
|
|
|
|
|
r")*" # match one or more context string (?wat this should be 0 or 1) |
|
|
|
|
|
# END: python context search |
|
|
|
|
|
|
|
|
|
|
|
# BEGIN: JS context search |
|
|
|
|
|
r"(\s*,\s*(.)*?\s*(,\s*" # skip message format replacements: ["format", ...] | null | [] |
|
|
|
|
|
r"([\"'])" # start of context string; 11th capture group |
|
|
|
|
|
r"(?P<js_context>((?!\11).)*)" # capture context string till closing id is found |
|
|
|
|
|
r"\11" # match context string closure |
|
|
|
|
|
r")*" |
|
|
|
|
|
r")*" # match one or more context string |
|
|
|
|
|
# END: JS context search |
|
|
|
|
|
|
|
|
|
|
|
r"\)" # Closing function call |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_language(lang_list: List = None) -> str: |
|
|
def get_language(lang_list: List = None) -> str: |
|
|
"""Set `frappe.local.lang` from HTTP headers at beginning of request |
|
|
"""Set `frappe.local.lang` from HTTP headers at beginning of request |
|
@@ -651,9 +680,8 @@ def extract_messages_from_code(code): |
|
|
frappe.clear_last_message() |
|
|
frappe.clear_last_message() |
|
|
|
|
|
|
|
|
messages = [] |
|
|
messages = [] |
|
|
pattern = r"_\(([\"']{,3})(?P<message>((?!\1).)*)\1(\s*,\s*context\s*=\s*([\"'])(?P<py_context>((?!\5).)*)\5)*(\s*,\s*(.)*?\s*(,\s*([\"'])(?P<js_context>((?!\11).)*)\11)*)*\)" |
|
|
|
|
|
|
|
|
|
|
|
for m in re.compile(pattern).finditer(code): |
|
|
|
|
|
|
|
|
for m in TRANSLATE_PATTERN.finditer(code): |
|
|
message = m.group('message') |
|
|
message = m.group('message') |
|
|
context = m.group('py_context') or m.group('js_context') |
|
|
context = m.group('py_context') or m.group('js_context') |
|
|
pos = m.start() |
|
|
pos = m.start() |
|
|