diff --git a/babel_extractors.csv b/babel_extractors.csv index 7f2103c4d4..db6c515efc 100644 --- a/babel_extractors.csv +++ b/babel_extractors.csv @@ -5,8 +5,9 @@ hooks.py,frappe.gettext.extractors.navbar.extract **/module_onboarding/*/*.json,frappe.gettext.extractors.module_onboarding.extract **/report/*/*.json,frappe.gettext.extractors.report.extract **.py,frappe.gettext.extractors.python.extract +templates/**.js,frappe.gettext.extractors.html_template.extract **.js,frappe.gettext.extractors.javascript.extract **.html,frappe.gettext.extractors.html_template.extract **.vue,frappe.gettext.extractors.html_template.extract **/custom/*.json,frappe.gettext.extractors.customization.extract -**/fixtures/custom_field.json,frappe.gettext.extractors.custom_field.extract \ No newline at end of file +**/fixtures/custom_field.json,frappe.gettext.extractors.custom_field.extract diff --git a/frappe/gettext/extractors/javascript.py b/frappe/gettext/extractors/javascript.py index 18063c2d38..25b696d20d 100644 --- a/frappe/gettext/extractors/javascript.py +++ b/frappe/gettext/extractors/javascript.py @@ -4,7 +4,7 @@ from io import BufferedReader def extract(fileobj: BufferedReader, keywords: str, comment_tags: tuple, options: dict): code = fileobj.read().decode("utf-8") - for lineno, funcname, messages in extract_javascript(code, "__", options): + for lineno, funcname, messages in extract_javascript(code, options=options): if not messages or not messages[0]: continue @@ -22,7 +22,7 @@ def extract(fileobj: BufferedReader, keywords: str, comment_tags: tuple, options yield lineno, funcname, messages, [] -def extract_javascript(code, keywords=("__",), options=None, lineno=1): +def extract_javascript(code, keywords=None, options=None, lineno=1): """Extract messages from JavaScript source code. This is a modified version of babel's JS parser. Reused under BSD license. @@ -40,6 +40,7 @@ def extract_javascript(code, keywords=("__",), options=None, lineno=1): :param code: code as string :param keywords: a list of keywords (i.e. function names) that should be recognized as translation functions + Defaults to ("__",) :param options: a dictionary of additional options (optional) Supported options are: * `template_string` -- set to false to disable ES6 template string support. @@ -49,6 +50,9 @@ def extract_javascript(code, keywords=("__",), options=None, lineno=1): if options is None: options = {} + if keywords is None: + keywords = ("__",) + funcname = message_lineno = None messages = [] last_argument = None diff --git a/frappe/translate.py b/frappe/translate.py index ebabd240eb..e4cb8f32bb 100644 --- a/frappe/translate.py +++ b/frappe/translate.py @@ -630,11 +630,7 @@ def extract_messages_from_javascript_code(code: str) -> list[tuple[int, str, str messages = [] from frappe.gettext.extractors.javascript import extract_javascript - for message in extract_javascript( - code, - keywords=["__"], - options={}, - ): + for message in extract_javascript(code): lineno, _func, args = message if not args or not args[0]: