diff --git a/frappe/gettext/extractors/workspace.py b/frappe/gettext/extractors/workspace.py new file mode 100644 index 0000000000..b1bc388b17 --- /dev/null +++ b/frappe/gettext/extractors/workspace.py @@ -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", []) + )