From 159ffa772b10fe4cb797cd5179b4cbfa6426dbac Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 19 Feb 2024 21:25:36 +0100 Subject: [PATCH] reuse dictionnary for nav tx content --- .github/workflows/website.yml | 6 +++--- website/scripts/mkdocs_tx.py | 16 ++++++---------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index bd0eee44..dd617e63 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -58,13 +58,13 @@ jobs: TX_TOKEN: ${{ secrets.TX_TOKEN }} - name: Push source files to Transifex - if: ${{ github.event_name == 'push' }} + if: ${{ github.event_name != 'pull_request' }} run: ./tx push env: TX_TOKEN: ${{ secrets.TX_TOKEN }} - name: Pull translations from Transifex - if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == 'opengisch/signalo' && github.actor != 'dependabot[bot]' }} + if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'opengisch/signalo' && github.actor != 'dependabot[bot]' }} run: | ./tx pull --translations --all --minimum-perc 10 ./tx status @@ -72,7 +72,7 @@ jobs: TX_TOKEN: ${{ secrets.TX_TOKEN }} - name: Translate Mkdocs config - if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == 'opengisch/signalo' && github.actor != 'dependabot[bot]' }} + if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'opengisch/signalo' && github.actor != 'dependabot[bot]' }} run: | ./scripts/mkdocs_tx.py -s fr update_config ./scripts/mkdocs_tx_commit.sh diff --git a/website/scripts/mkdocs_tx.py b/website/scripts/mkdocs_tx.py index 074e1c5d..23812d6e 100755 --- a/website/scripts/mkdocs_tx.py +++ b/website/scripts/mkdocs_tx.py @@ -19,11 +19,11 @@ def read_config(file_path: str): def nav_config(config): - _nav_config = [] + _nav_config = {} def add_nav_entry(title, content): if title: - _nav_config.append(title) + _nav_config[title] = title for _entry in content: if type(_entry) == str: # this is pointing to a page directly, skipping @@ -57,7 +57,6 @@ def create_translation_source(config_path, source_path): def update_config(config_path, source_path, source_language): config = read_config(config_path) - _nav_config = nav_config(config) found = False for plugin in config["plugins"]: @@ -76,13 +75,10 @@ def update_config(config_path, source_path, source_language): yaml = YAML() tx = yaml.load(f) - 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] - ) + for _title, _translation in tx["nav"].items(): + if not _translation: + tx["nav"][_title] = _title + lang["nav_translations"] = tx["nav"] try: lang["palette"] = copy.deepcopy(config["theme"]["palette"])