feat: navbar extractor
This commit is contained in:
parent
30c8ffb600
commit
6b1e12e49b
1 changed files with 41 additions and 0 deletions
41
frappe/gettext/extractors/navbar.py
Normal file
41
frappe/gettext/extractors/navbar.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import importlib
|
||||
from pathlib import Path
|
||||
|
||||
from frappe.utils import get_bench_path
|
||||
|
||||
|
||||
def extract(fileobj, *args, **kwargs):
|
||||
"""Extract standard navbar and help items from a python file.
|
||||
|
||||
:param fileobj: file-like object to extract messages from. Should be a
|
||||
python file containing two global variables `standard_navbar_items` and
|
||||
`standard_help_items` which are lists of dicts.
|
||||
"""
|
||||
# import variables standard_navbar_items and standard_help_items from the
|
||||
# given python file
|
||||
module = get_module(fileobj.name)
|
||||
standard_navbar_items = getattr(module, "standard_navbar_items")
|
||||
standard_help_items = getattr(module, "standard_help_items")
|
||||
|
||||
for nav_item in standard_navbar_items:
|
||||
if label := nav_item.get("item_label"):
|
||||
item_type = nav_item.get("item_type")
|
||||
yield None, "_", label, [
|
||||
"Label of a standard navbar item",
|
||||
f"Type: {item_type}",
|
||||
]
|
||||
|
||||
for help_item in standard_help_items:
|
||||
if label := help_item.get("item_label"):
|
||||
item_type = nav_item.get("item_type")
|
||||
yield None, "_", label, [
|
||||
"Label of a standard help item",
|
||||
f"Type: {item_type}",
|
||||
]
|
||||
|
||||
|
||||
def get_module(path):
|
||||
_path = Path(path)
|
||||
rel_path = _path.relative_to(get_bench_path())
|
||||
import_path = ".".join(rel_path.parts[2:]).rstrip(".py")
|
||||
return importlib.import_module(import_path)
|
||||
Loading…
Add table
Reference in a new issue