From 1d0a11ee5bdca69a0db1533b3d9b0ee69ff66479 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 19 Feb 2024 15:43:32 +0100 Subject: [PATCH] fix depth in nav --- website/scripts/mkdocs_tx.py | 40 ++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/website/scripts/mkdocs_tx.py b/website/scripts/mkdocs_tx.py index 6712514a..c098c1ce 100755 --- a/website/scripts/mkdocs_tx.py +++ b/website/scripts/mkdocs_tx.py @@ -18,14 +18,26 @@ def read_config(file_path: str): return yaml.load(f) +def nav_config(config): + _nav_config = [] + + def add_nav_entry(_title, _content): + if type(_content) == str: + _nav_config.append(_title) + else: + for _entry in _content: + for title, content in _entry.items(): + add_nav_entry(title, content) + + add_nav_entry(None, config["nav"]) + + return _nav_config + + def create_translation_source(config_path, source_path): config = read_config(config_path) - nav_config = [] - for _entry in config["nav"]: - nav_config.append({v: k for k, v in _entry.items()}) - - tx_cfg = {"nav": nav_config} + tx_cfg = {"nav": nav_config(config)} try: tx_cfg["theme"] = {"palette": []} @@ -43,11 +55,7 @@ def create_translation_source(config_path, source_path): def update_config(config_path, source_path, source_language): config = read_config(config_path) - - nav_config = {} - for _entry in config["nav"]: - for title, page in _entry.items(): - nav_config[page] = title + _nav_config = nav_config(config) found = False for plugin in config["plugins"]: @@ -66,11 +74,13 @@ def update_config(config_path, source_path, source_language): yaml = YAML() tx = yaml.load(f) - for nav_entry in tx["nav"]: - for page, title in nav_entry.items(): - source_language_tile = nav_config[page] - if title: - lang["nav_translations"][source_language_tile] = title + assert len(_nav_config) == len(tx["nav"]) + + lang["nav_translations"] = {} + for i in range(len(tx["nav"])): + lang["nav_translations"][_nav_config[i]] = ( + tx["nav"][i] or _nav_config[i] + ) try: lang["palette"] = copy.deepcopy(config["theme"]["palette"])