fix(translate): Fix extraction in JS files (#27401)
Co-authored-by: barredterra <14891507+barredterra@users.noreply.github.com>
This commit is contained in:
parent
2c7852e6aa
commit
35fb0e2687
3 changed files with 9 additions and 8 deletions
|
|
@ -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
|
||||
**/fixtures/custom_field.json,frappe.gettext.extractors.custom_field.extract
|
||||
|
|
|
|||
|
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue