feat: workspace extractor
This commit is contained in:
parent
abcafafca9
commit
bd9bb6d0d6
1 changed files with 42 additions and 0 deletions
42
frappe/gettext/extractors/workspace.py
Normal file
42
frappe/gettext/extractors/workspace.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import json
|
||||
|
||||
|
||||
def extract(fileobj, *args, **kwargs):
|
||||
"""
|
||||
Extract messages from DocType JSON files. To be used to babel extractor
|
||||
:param fileobj: the file-like object the messages should be extracted from
|
||||
:rtype: `iterator`
|
||||
"""
|
||||
data = json.load(fileobj)
|
||||
|
||||
if isinstance(data, list):
|
||||
return
|
||||
|
||||
if data.get("doctype") != "Workspace":
|
||||
return
|
||||
|
||||
workspace_name = data.get("label")
|
||||
|
||||
yield None, "_", workspace_name, ["Name of a Workspace"]
|
||||
yield from (
|
||||
(None, "_", chart.get("label"), [f"Label of a chart in the {workspace_name} Workspace"])
|
||||
for chart in data.get("charts", [])
|
||||
)
|
||||
yield from (
|
||||
(
|
||||
None,
|
||||
"pgettext",
|
||||
(link.get("link_to") if link.get("link_type") == "DocType" else None, link.get("label")),
|
||||
[f"Label of a {link.get('type')} in the {workspace_name} Workspace"],
|
||||
)
|
||||
for link in data.get("links", [])
|
||||
)
|
||||
yield from (
|
||||
(
|
||||
None,
|
||||
"pgettext",
|
||||
(shortcut.get("link_to") if shortcut.get("type") == "DocType" else None, shortcut.get("label")),
|
||||
[f"Label of a shortcut in the {workspace_name} Workspace"],
|
||||
)
|
||||
for shortcut in data.get("shortcuts", [])
|
||||
)
|
||||
Loading…
Add table
Reference in a new issue