From 4b0f3e7fa485975c9c83104aa52841e2589a7ece Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 19 Feb 2024 15:13:13 +0100 Subject: [PATCH 01/17] translate MkDocs navigation content on Transifex --- .github/workflows/doc.yml | 21 +++-- docs/requirements-dev.txt | 2 + docs/scripts/mkdocs_tx.py | 133 +++++++++++++++++++++++++++++++ docs/scripts/mkdocs_tx_commit.sh | 31 +++++++ docs/scripts/transifex_utils.py | 11 +++ 5 files changed, 193 insertions(+), 5 deletions(-) create mode 100644 docs/requirements-dev.txt create mode 100755 docs/scripts/mkdocs_tx.py create mode 100755 docs/scripts/mkdocs_tx_commit.sh diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 360b2e77b..b600f1aa5 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -8,15 +8,13 @@ on: - '.github/workflows/doc.yml' push: branches: + - docx # TODO: remove - master paths: - 'docs/**' - '.github/workflows/doc.yml' workflow_dispatch: # useful for testing tx pushes - workflow_call: -permissions: - contents: write defaults: run: @@ -37,13 +35,18 @@ jobs: python-version: '3.10' - name: Install Python requirements - run: pip install -r requirements.txt + run: | + pip install -r requirements.txt + pip install -r requirements-dev.txt - name: Install Transifex client run: | curl -OL https://github.com/transifex/cli/releases/download/v1.6.10/tx-linux-amd64.tar.gz tar -xvzf tx-linux-amd64.tar.gz + - name: Extract translatable content from mkdocs.yml config + run: ./scripts/mkdocs_tx.py create_source + - name: Configure Transifex run: scripts/transifex_utils.py env: @@ -56,13 +59,21 @@ jobs: TX_TOKEN: ${{ secrets.TX_TOKEN }} - name: Pull translations from Transifex - if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name == 'opengisch/QgisModelBaker' && github.actor != 'dependabot[bot]' }} + if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == 'opengisch/QgisModelBaker' && github.actor != 'dependabot[bot]' }} run: | ./tx pull --translations --all --minimum-perc 10 ./tx status env: 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/QgisModelBaker' && github.actor != 'dependabot[bot]' }} + run: | + ./scripts/mkdocs_tx.py -s fr update_config + ./scripts/mkdocs_tx_commit.sh + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Build documentation run: mkdocs build diff --git a/docs/requirements-dev.txt b/docs/requirements-dev.txt new file mode 100644 index 000000000..f3d7632ed --- /dev/null +++ b/docs/requirements-dev.txt @@ -0,0 +1,2 @@ +ruamel.yaml==0.18.6 +pre-commit==3.6.2 diff --git a/docs/scripts/mkdocs_tx.py b/docs/scripts/mkdocs_tx.py new file mode 100755 index 000000000..6712514ab --- /dev/null +++ b/docs/scripts/mkdocs_tx.py @@ -0,0 +1,133 @@ +#!/usr/bin/env python + +import argparse +import copy + +from ruamel.yaml import YAML + +# This scripts helps with translatable content from mkdocs.yml +# It provides commands: +# * to create the YAML translatable file +# * to update the mkdocs.yml with the translated content + + +def read_config(file_path: str): + yaml = YAML(typ="rt") + yaml.preserve_quotes = True + with open(file_path) as f: + return yaml.load(f) + + +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} + + try: + tx_cfg["theme"] = {"palette": []} + for palette in config["theme"]["palette"]: + tx_cfg["theme"]["palette"].append( + {"toggle": {"name": palette["toggle"]["name"]}} + ) + except KeyError: + print("No theme/palette/toggle/name to translate") + + with open(source_path, "w") as f: + yaml = YAML() + yaml.dump(tx_cfg, f) + + +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 + + found = False + for plugin in config["plugins"]: + if type(plugin) != str and "i18n" in plugin: + found = True + for lang in plugin["i18n"]["languages"]: + ltx = lang["locale"] + print(f"language found: '{ltx}'") + + if ltx == source_language: + print("skipping source language") + continue + + tx_file = f'{source_path.removesuffix(".yml")}.{ltx}.yml' + with open(tx_file) as f: + 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 + + try: + lang["palette"] = copy.deepcopy(config["theme"]["palette"]) + i = 0 + for palette in tx["theme"]["palette"]: + lang["palette"][i]["toggle"]["name"] = palette["toggle"][ + "name" + ] + i += 1 + except KeyError: + print("No theme/palette/toggle/name to translate") + + assert found + + with open(config_path, "w") as f: + yaml = YAML() + yaml.indent(mapping=2, sequence=4, offset=2) + yaml.dump(config, f) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "-c", "--config_path", default="mkdocs.yml", help="mkdocs.yml complete path" + ) + parser.add_argument( + "-s", "--source_language", default="en", help="source language of the config" + ) + parser.add_argument( + "-t", + "--translation_file_path", + default="mkdocs_tx.yml", + help="Translation file to create and translate", + ) + + subparsers = parser.add_subparsers(title="command", dest="command") + + # create the parser for the create_source command + parser_source = subparsers.add_parser( + "create_source", help="Creates the source file to be translated" + ) + + # create the parser for the update_config command + parser_update = subparsers.add_parser( + "update_config", + help="Updates the mkdocs.yml config file from the downloaded translated files", + ) + + args = parser.parse_args() + + if args.command == "create_source": + create_translation_source(args.config_path, args.translation_file_path) + + elif args.command == "update_config": + update_config( + args.config_path, args.translation_file_path, args.source_language + ) + + else: + raise ValueError diff --git a/docs/scripts/mkdocs_tx_commit.sh b/docs/scripts/mkdocs_tx_commit.sh new file mode 100755 index 000000000..88f78f773 --- /dev/null +++ b/docs/scripts/mkdocs_tx_commit.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +set -e + +pre-commit install +pre-commit run --files mkdocs.yml || true + +if [[ $(git diff --exit-code mkdocs.yml) ]]; then + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git config --global user.name "github-actions[bot]" + + echo "detected changes in mkdocs.yml" + if [[ ${GITHUB_EVENT_NAME} == "pull_request" ]]; then + # on PR push to the same branch + gh pr checkout $(echo "${GITHUB_REF_NAME}" | cut -d/ -f1) + git add mkdocs.yml + git commit -m "Update mkdocs.yml translation" --no-verify + git push + else + # on push/workflow_dispatch create a pull request + git checkout ${GITHUB_REF_NAME} + BRANCH="update-mkdocs-tx-$RANDOM" + git checkout -b ${BRANCH} + git add mkdocs.yml + git commit -m "Update mkdocs.yml translation" --no-verify + git push -u origin $BRANCH + gh pr create -B ${GITHUB_REF_NAME} -H ${BRANCH} --title 'Update mkdocs translations' --body 'run from mkdocs_tx' + fi +else + echo "no change mkdocs.yml" +fi diff --git a/docs/scripts/transifex_utils.py b/docs/scripts/transifex_utils.py index ca148f773..c0f5259b0 100755 --- a/docs/scripts/transifex_utils.py +++ b/docs/scripts/transifex_utils.py @@ -26,6 +26,17 @@ def create_transifex_config(): f.write("[main]\n") f.write("host = https://www.transifex.com\n\n") + if os.path.isfile(f"{root}/mkdocs_tx.yml"): + print(f"Found mkdocs config translated content") + f.write(f"[o:{TX_ORGANIZATION}:p:{TX_PROJECT}:r:site_navigation]\n") + f.write("resource_name = site navigation\n") + f.write("file_filter = mkdocs_tx..yml\n") + f.write(f"source_file = mkdocs_tx.yml\n") + f.write(f"source_lang = {TX_SOURCE_LANG}\n") + f.write(f"type = YAML_GENERIC\n\n") + else: + print("No translation of mkdocs config found") + for file in glob.iglob(current_dir + "/../docs/**/*.md", recursive=True): # Get relative path of file relative_path = os.path.relpath(file, start=root) From bdd0c5e5fffb8e9794ed17aba31afcbbd73ac9a6 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 19 Feb 2024 15:29:22 +0100 Subject: [PATCH 02/17] fix depth nav --- docs/scripts/mkdocs_tx.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/scripts/mkdocs_tx.py b/docs/scripts/mkdocs_tx.py index 6712514ab..294205cb7 100755 --- a/docs/scripts/mkdocs_tx.py +++ b/docs/scripts/mkdocs_tx.py @@ -22,8 +22,16 @@ 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()}) + + 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"]) tx_cfg = {"nav": nav_config} From 412c99afce742662ff106fd599d9528c39282b62 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 19 Feb 2024 15:44:26 +0100 Subject: [PATCH 03/17] fix depth in nav --- docs/scripts/mkdocs_tx.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/docs/scripts/mkdocs_tx.py b/docs/scripts/mkdocs_tx.py index 294205cb7..c098c1ceb 100755 --- a/docs/scripts/mkdocs_tx.py +++ b/docs/scripts/mkdocs_tx.py @@ -18,14 +18,12 @@ def read_config(file_path: str): return yaml.load(f) -def create_translation_source(config_path, source_path): - config = read_config(config_path) - - nav_config = [] +def nav_config(config): + _nav_config = [] def add_nav_entry(_title, _content): if type(_content) == str: - nav_config.append(_title) + _nav_config.append(_title) else: for _entry in _content: for title, content in _entry.items(): @@ -33,7 +31,13 @@ def add_nav_entry(_title, _content): add_nav_entry(None, config["nav"]) - tx_cfg = {"nav": nav_config} + return _nav_config + + +def create_translation_source(config_path, source_path): + config = read_config(config_path) + + tx_cfg = {"nav": nav_config(config)} try: tx_cfg["theme"] = {"palette": []} @@ -51,11 +55,7 @@ def add_nav_entry(_title, _content): 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"]: @@ -74,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"]) From 015224470f7ac6f59bcd8acd0f50d7432afab147 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 19 Feb 2024 15:47:25 +0100 Subject: [PATCH 04/17] fix --- .github/workflows/doc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index b600f1aa5..b1a7a94b8 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -69,7 +69,7 @@ jobs: - name: Translate Mkdocs config if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == 'opengisch/QgisModelBaker' && github.actor != 'dependabot[bot]' }} run: | - ./scripts/mkdocs_tx.py -s fr update_config + ./scripts/mkdocs_tx.py -s en update_config ./scripts/mkdocs_tx_commit.sh env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 685e3321c41fcb5c417d15cbf13568e64f47b9ec Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 19 Feb 2024 15:52:34 +0100 Subject: [PATCH 05/17] fix --- docs/scripts/mkdocs_tx.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/scripts/mkdocs_tx.py b/docs/scripts/mkdocs_tx.py index c098c1ceb..28b51f5f1 100755 --- a/docs/scripts/mkdocs_tx.py +++ b/docs/scripts/mkdocs_tx.py @@ -86,9 +86,11 @@ def update_config(config_path, source_path, source_language): lang["palette"] = copy.deepcopy(config["theme"]["palette"]) i = 0 for palette in tx["theme"]["palette"]: - lang["palette"][i]["toggle"]["name"] = palette["toggle"][ - "name" - ] + _name = ( + palette["toggle"]["name"] + or config["theme"]["palette"][i]["toggle"]["name"] + ) + lang["palette"][i]["toggle"]["name"] = _name i += 1 except KeyError: print("No theme/palette/toggle/name to translate") From 8061422785b5e08964c6d4a6876ff99ae15e518d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 19 Feb 2024 15:54:10 +0100 Subject: [PATCH 06/17] Update mkdocs.yml translation (#886) Co-authored-by: github-actions[bot] --- docs/mkdocs.yml | 52 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index b4614c375..d6ea55a24 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -39,23 +39,23 @@ theme: nav: - Home: index.md - User Guide: - - Get Started: user_guide/get_started.md - - Model and Data Import Workflow: user_guide/import_workflow.md - - Export Data Workflow: user_guide/export_workflow.md - - Validate Data: user_guide/validation.md - - Plugin Configuration: user_guide/plugin_configuration.md + - Get Started: user_guide/get_started.md + - Model and Data Import Workflow: user_guide/import_workflow.md + - Export Data Workflow: user_guide/export_workflow.md + - Validate Data: user_guide/validation.md + - Plugin Configuration: user_guide/plugin_configuration.md - Tipps & Tricks: - - Repositories: background_info/repositories.md - - Basket and Dataset Handling: background_info/basket_handling.md - - OID Generator: background_info/oid_tid_generator.md - - UsabILIty Hub: - - Model Baker Integration: background_info/usabilityhub/modelbaker_integration.md - - Technical Concept: background_info/usabilityhub/technical_concept.md - - User Guide: background_info/usabilityhub/user_guide.md - - Optimized Projects for Extended Models: background_info/extended_models_optimization.md - - Catalogues and their special cases: background_info/catalogues.md - - Meta Attributes: background_info/meta_attributes.md - - Migrate from ili2db 3 to 4: background_info/upgrade_3_to_4.md + - Repositories: background_info/repositories.md + - Basket and Dataset Handling: background_info/basket_handling.md + - OID Generator: background_info/oid_tid_generator.md + - UsabILIty Hub: + - Model Baker Integration: background_info/usabilityhub/modelbaker_integration.md + - Technical Concept: background_info/usabilityhub/technical_concept.md + - User Guide: background_info/usabilityhub/user_guide.md + - Optimized Projects for Extended Models: background_info/extended_models_optimization.md + - Catalogues and their special cases: background_info/catalogues.md + - Meta Attributes: background_info/meta_attributes.md + - Migrate from ili2db 3 to 4: background_info/upgrade_3_to_4.md #- Relations in QGIS: maybe from here https://github.com/signedav/interlis_relations_in_qgis #- INTERLIS Syntax in 10 Minutes: maybe stuff from here https://github.com/signedav/talk_iliuniverse - Development: development.md @@ -78,7 +78,7 @@ plugins: name: Deutsch site_name: QGIS Model Baker Dokumentation nav_translations: - User Guide: Benutzerhandbuch + Home: Home Get Started: Loslegen Model and Data Import Workflow: Modell und Daten Import Workflow Export Data Workflow: Daten Export Workflow @@ -87,10 +87,26 @@ plugins: Repositories: Repositories Basket and Dataset Handling: Dataset und Basket Handling OID Generator: OID Generator - Optimized Projects for Extended Models : Optimierte Projekte für erweiterte Modelle Model Baker Integration: Model Baker Integration Technical Concept: Technisches Konzept + User Guide: Benutzerhandbuch + Optimized Projects for Extended Models: Optimierte Projekte für erweiterte + Modelle Catalogues and their special cases: Kataloge und ihre Spezialfälle Meta Attributes: Metaattribute Migrate from ili2db 3 to 4: Migration von ili2db 3 zu 4 Development: Enwicklung + palette: + - scheme: default + primary: blue grey + toggle: + icon: material/weather-night + name: Switch to dark mode + - scheme: slate + primary: blue grey + toggle: + icon: material/weather-sunny + name: Switch to light mode + primary: white + +# Page tree From cc285df3ebf7bf53450525d77b98996dd5dabd80 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 19 Feb 2024 15:54:40 +0100 Subject: [PATCH 07/17] remove TODO --- .github/workflows/doc.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index b1a7a94b8..e959d0cd5 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -8,7 +8,6 @@ on: - '.github/workflows/doc.yml' push: branches: - - docx # TODO: remove - master paths: - 'docs/**' From 89c49007d790aa8f701c6a192ec38b83cc9719c0 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 19 Feb 2024 19:58:28 +0100 Subject: [PATCH 08/17] update on dispatch --- .github/workflows/doc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index e959d0cd5..1c46b7877 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -84,5 +84,5 @@ jobs: if-no-files-found: error - name: Deploy to GitHub Pages - if: ${{ github.event_name == 'push' }} + if: ${{ github.event_name != 'pull_request' }} run: mkdocs gh-deploy --force From ba989c31d11591ab053e185bc68c91b9fc8b5977 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 19 Feb 2024 20:17:13 +0100 Subject: [PATCH 09/17] better script --- docs/scripts/mkdocs_tx.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/scripts/mkdocs_tx.py b/docs/scripts/mkdocs_tx.py index 28b51f5f1..074e1c5df 100755 --- a/docs/scripts/mkdocs_tx.py +++ b/docs/scripts/mkdocs_tx.py @@ -21,13 +21,15 @@ def read_config(file_path: str): 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) + def add_nav_entry(title, content): + if title: + _nav_config.append(title) + for _entry in content: + if type(_entry) == str: + # this is pointing to a page directly, skipping + continue + for _title, _content in _entry.items(): + add_nav_entry(_title, _content) add_nav_entry(None, config["nav"]) From 0902a52613ebafd59b76fd56a269e834583bc7ad Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 19 Feb 2024 21:10:27 +0100 Subject: [PATCH 10/17] simplify --- .github/workflows/doc.yml | 3 ++- docs/mkdocs.yml | 31 +++++++++++++++++-------------- docs/scripts/mkdocs_tx.py | 14 ++++---------- mkdocs_tx.de.yml | 27 +++++++++++++++++++++++++++ mkdocs_tx.yml | 26 ++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 25 deletions(-) create mode 100644 mkdocs_tx.de.yml create mode 100644 mkdocs_tx.yml diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 1c46b7877..22b4255dc 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -9,6 +9,7 @@ on: push: branches: - master + - docx # TODO remove paths: - 'docs/**' - '.github/workflows/doc.yml' @@ -52,7 +53,7 @@ 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 }} diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index d6ea55a24..a61a25bf5 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -79,23 +79,26 @@ plugins: site_name: QGIS Model Baker Dokumentation nav_translations: Home: Home - Get Started: Loslegen - Model and Data Import Workflow: Modell und Daten Import Workflow - Export Data Workflow: Daten Export Workflow - Validate Data: Daten Validierung - Plugin Configuration: Plugin Konfiguration + User Guide: User Guide + Get Started: Get Started + Model and Data Import Workflow: Model and Data Import Workflow + Export Data Workflow: Export Data Workflow + Validate Data: Validate Data + Plugin Configuration: Plugin Configuration + Tipps & Tricks: Tipps & Tricks Repositories: Repositories - Basket and Dataset Handling: Dataset und Basket Handling + Basket and Dataset Handling: Basket and Dataset Handling OID Generator: OID Generator + UsabILIty Hub: UsabILIty Hub Model Baker Integration: Model Baker Integration - Technical Concept: Technisches Konzept - User Guide: Benutzerhandbuch - Optimized Projects for Extended Models: Optimierte Projekte für erweiterte - Modelle - Catalogues and their special cases: Kataloge und ihre Spezialfälle - Meta Attributes: Metaattribute - Migrate from ili2db 3 to 4: Migration von ili2db 3 zu 4 - Development: Enwicklung + Technical Concept: Technical Concept + Optimized Projects for Extended Models: Optimized Projects for Extended + Models + Catalogues and their special cases: Catalogues and their special cases + Meta Attributes: Meta Attributes + Migrate from ili2db 3 to 4: Migrate from ili2db 3 to 4 + Development: Development + palette: - scheme: default primary: blue grey diff --git a/docs/scripts/mkdocs_tx.py b/docs/scripts/mkdocs_tx.py index 074e1c5df..cf6fac81e 100755 --- a/docs/scripts/mkdocs_tx.py +++ b/docs/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,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 = nav_config(config) + nav_config(config) found = False for plugin in config["plugins"]: @@ -76,13 +76,7 @@ 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] - ) + lang["nav_translations"] = tx["nav"] try: lang["palette"] = copy.deepcopy(config["theme"]["palette"]) diff --git a/mkdocs_tx.de.yml b/mkdocs_tx.de.yml new file mode 100644 index 000000000..cdacc247e --- /dev/null +++ b/mkdocs_tx.de.yml @@ -0,0 +1,27 @@ +nav: + Home: Home + User Guide: User Guide + Get Started: Get Started + Model and Data Import Workflow: Model and Data Import Workflow + Export Data Workflow: Export Data Workflow + Validate Data: Validate Data + Plugin Configuration: Plugin Configuration + Tipps & Tricks: Tipps & Tricks + Repositories: Repositories + Basket and Dataset Handling: Basket and Dataset Handling + OID Generator: OID Generator + UsabILIty Hub: UsabILIty Hub + Model Baker Integration: Model Baker Integration + Technical Concept: Technical Concept + Optimized Projects for Extended Models: Optimized Projects for Extended Models + Catalogues and their special cases: Catalogues and their special cases + Meta Attributes: Meta Attributes + Migrate from ili2db 3 to 4: Migrate from ili2db 3 to 4 + Development: Development + +theme: + palette: + - toggle: + name: "" + - toggle: + name: "" diff --git a/mkdocs_tx.yml b/mkdocs_tx.yml new file mode 100644 index 000000000..27286e090 --- /dev/null +++ b/mkdocs_tx.yml @@ -0,0 +1,26 @@ +nav: + Home: Home + User Guide: User Guide + Get Started: Get Started + Model and Data Import Workflow: Model and Data Import Workflow + Export Data Workflow: Export Data Workflow + Validate Data: Validate Data + Plugin Configuration: Plugin Configuration + Tipps & Tricks: Tipps & Tricks + Repositories: Repositories + Basket and Dataset Handling: Basket and Dataset Handling + OID Generator: OID Generator + UsabILIty Hub: UsabILIty Hub + Model Baker Integration: Model Baker Integration + Technical Concept: Technical Concept + Optimized Projects for Extended Models: Optimized Projects for Extended Models + Catalogues and their special cases: Catalogues and their special cases + Meta Attributes: Meta Attributes + Migrate from ili2db 3 to 4: Migrate from ili2db 3 to 4 + Development: Development +theme: + palette: + - toggle: + name: Switch to dark mode + - toggle: + name: Switch to light mode From 9b34537b1ce5dc03cdac9f10aa7fcb2871978972 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 19 Feb 2024 21:10:48 +0100 Subject: [PATCH 11/17] remove extra files --- mkdocs_tx.de.yml | 27 --------------------------- mkdocs_tx.yml | 26 -------------------------- 2 files changed, 53 deletions(-) delete mode 100644 mkdocs_tx.de.yml delete mode 100644 mkdocs_tx.yml diff --git a/mkdocs_tx.de.yml b/mkdocs_tx.de.yml deleted file mode 100644 index cdacc247e..000000000 --- a/mkdocs_tx.de.yml +++ /dev/null @@ -1,27 +0,0 @@ -nav: - Home: Home - User Guide: User Guide - Get Started: Get Started - Model and Data Import Workflow: Model and Data Import Workflow - Export Data Workflow: Export Data Workflow - Validate Data: Validate Data - Plugin Configuration: Plugin Configuration - Tipps & Tricks: Tipps & Tricks - Repositories: Repositories - Basket and Dataset Handling: Basket and Dataset Handling - OID Generator: OID Generator - UsabILIty Hub: UsabILIty Hub - Model Baker Integration: Model Baker Integration - Technical Concept: Technical Concept - Optimized Projects for Extended Models: Optimized Projects for Extended Models - Catalogues and their special cases: Catalogues and their special cases - Meta Attributes: Meta Attributes - Migrate from ili2db 3 to 4: Migrate from ili2db 3 to 4 - Development: Development - -theme: - palette: - - toggle: - name: "" - - toggle: - name: "" diff --git a/mkdocs_tx.yml b/mkdocs_tx.yml deleted file mode 100644 index 27286e090..000000000 --- a/mkdocs_tx.yml +++ /dev/null @@ -1,26 +0,0 @@ -nav: - Home: Home - User Guide: User Guide - Get Started: Get Started - Model and Data Import Workflow: Model and Data Import Workflow - Export Data Workflow: Export Data Workflow - Validate Data: Validate Data - Plugin Configuration: Plugin Configuration - Tipps & Tricks: Tipps & Tricks - Repositories: Repositories - Basket and Dataset Handling: Basket and Dataset Handling - OID Generator: OID Generator - UsabILIty Hub: UsabILIty Hub - Model Baker Integration: Model Baker Integration - Technical Concept: Technical Concept - Optimized Projects for Extended Models: Optimized Projects for Extended Models - Catalogues and their special cases: Catalogues and their special cases - Meta Attributes: Meta Attributes - Migrate from ili2db 3 to 4: Migrate from ili2db 3 to 4 - Development: Development -theme: - palette: - - toggle: - name: Switch to dark mode - - toggle: - name: Switch to light mode From 00036bf46d90c1814ea46d7fae12cb64acc5b1d9 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 19 Feb 2024 21:21:36 +0100 Subject: [PATCH 12/17] fallback --- .github/workflows/doc.yml | 1 - docs/scripts/mkdocs_tx.py | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 22b4255dc..c946a47db 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -9,7 +9,6 @@ on: push: branches: - master - - docx # TODO remove paths: - 'docs/**' - '.github/workflows/doc.yml' diff --git a/docs/scripts/mkdocs_tx.py b/docs/scripts/mkdocs_tx.py index cf6fac81e..23812d6e7 100755 --- a/docs/scripts/mkdocs_tx.py +++ b/docs/scripts/mkdocs_tx.py @@ -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(config) found = False for plugin in config["plugins"]: @@ -76,6 +75,9 @@ def update_config(config_path, source_path, source_language): yaml = YAML() tx = yaml.load(f) + for _title, _translation in tx["nav"].items(): + if not _translation: + tx["nav"][_title] = _title lang["nav_translations"] = tx["nav"] try: From 4797bc2608dae0dc4960f34e4db69ac901692404 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 19 Feb 2024 20:22:46 +0000 Subject: [PATCH 13/17] Update mkdocs.yml translation --- docs/mkdocs.yml | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index a61a25bf5..166861199 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -79,26 +79,25 @@ plugins: site_name: QGIS Model Baker Dokumentation nav_translations: Home: Home - User Guide: User Guide - Get Started: Get Started - Model and Data Import Workflow: Model and Data Import Workflow - Export Data Workflow: Export Data Workflow - Validate Data: Validate Data - Plugin Configuration: Plugin Configuration + User Guide: Benutzerhandbuch + Get Started: Loslegen + Model and Data Import Workflow: Modell und Daten Import Workflow + Export Data Workflow: Daten Export Workflow + Validate Data: Daten Validierung + Plugin Configuration: Plugin Konfiguration Tipps & Tricks: Tipps & Tricks Repositories: Repositories - Basket and Dataset Handling: Basket and Dataset Handling + Basket and Dataset Handling: Dataset und Basket Handling OID Generator: OID Generator UsabILIty Hub: UsabILIty Hub Model Baker Integration: Model Baker Integration - Technical Concept: Technical Concept - Optimized Projects for Extended Models: Optimized Projects for Extended - Models - Catalogues and their special cases: Catalogues and their special cases - Meta Attributes: Meta Attributes - Migrate from ili2db 3 to 4: Migrate from ili2db 3 to 4 - Development: Development - + Technical Concept: Technisches Konzept + Optimized Projects for Extended Models: Optimierte Projekte für erweiterte + Modelle + Catalogues and their special cases: Kataloge und ihre Spezialfälle + Meta Attributes: Metaattribute + Migrate from ili2db 3 to 4: Migration von ili2db 3 zu 4 + Development: Enwicklung palette: - scheme: default primary: blue grey From 23a41c4c92cb6a13a7874fb960036a1a619717ea Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 19 Feb 2024 21:25:10 +0100 Subject: [PATCH 14/17] simplify workflow --- .github/workflows/doc.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index c946a47db..363a170a6 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -58,7 +58,7 @@ jobs: 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/QgisModelBaker' && github.actor != 'dependabot[bot]' }} + if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'opengisch/QgisModelBaker' && github.actor != 'dependabot[bot]' }} run: | ./tx pull --translations --all --minimum-perc 10 ./tx status @@ -66,7 +66,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/QgisModelBaker' && github.actor != 'dependabot[bot]' }} + if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'opengisch/QgisModelBaker' && github.actor != 'dependabot[bot]' }} run: | ./scripts/mkdocs_tx.py -s en update_config ./scripts/mkdocs_tx_commit.sh From bba7d79de8c925a4db336b8e2bea7cc14112686c Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 19 Feb 2024 22:22:34 +0100 Subject: [PATCH 15/17] remove unused site_description + update script --- docs/mkdocs.yml | 2 -- docs/scripts/mkdocs_tx.py | 47 +++++++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 166861199..080a6d163 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -1,7 +1,5 @@ # Project information site_name: QGIS Model Baker Documentation -site_description: >- - This site contains documentation about QGIS Model Baker site_url: https://opengisch.github.io/QgisModelBaker/ docs_dir: docs diff --git a/docs/scripts/mkdocs_tx.py b/docs/scripts/mkdocs_tx.py index 23812d6e7..47797fe65 100755 --- a/docs/scripts/mkdocs_tx.py +++ b/docs/scripts/mkdocs_tx.py @@ -36,10 +36,40 @@ def add_nav_entry(title, content): return _nav_config -def create_translation_source(config_path, source_path): +def get_site_description(config, source_language): + site_description = None + found = 0 + try: + site_description = config["site_description"] + found += 1 + except KeyError: + pass + try: + for plugin in config["plugins"]: + if type(plugin) != str and "i18n" in plugin: + for lang in plugin["i18n"]["languages"]: + ltx = lang["locale"] + if ltx == source_language: + site_description = lang["site_description"] + found += 1 + except KeyError: + pass + if not found: + print("No site description found") + elif found > 1 and tx_cfg["site_description"] != config["site_description"]: + print("ERROR: site description found twice and different") + assert False + + return site_description + + +def create_translation_source(config_path, source_path, source_language): config = read_config(config_path) - tx_cfg = {"nav": nav_config(config)} + tx_cfg = { + "nav": nav_config(config), + "site_description": get_site_description(config, source_language), + } try: tx_cfg["theme"] = {"palette": []} @@ -80,6 +110,13 @@ def update_config(config_path, source_path, source_language): tx["nav"][_title] = _title lang["nav_translations"] = tx["nav"] + try: + lang["site_description"] = tx[ + "site_description" + ] or get_site_description(config, source_language) + except KeyError: + print("No site description in translation") + try: lang["palette"] = copy.deepcopy(config["theme"]["palette"]) i = 0 @@ -91,7 +128,7 @@ def update_config(config_path, source_path, source_language): lang["palette"][i]["toggle"]["name"] = _name i += 1 except KeyError: - print("No theme/palette/toggle/name to translate") + print("No theme/palette/toggle/name in translation") assert found @@ -132,7 +169,9 @@ def update_config(config_path, source_path, source_language): args = parser.parse_args() if args.command == "create_source": - create_translation_source(args.config_path, args.translation_file_path) + create_translation_source( + args.config_path, args.translation_file_path, args.source_language + ) elif args.command == "update_config": update_config( From cf6869334c3d15556f1a798313af02f81e1e1c22 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Thu, 22 Feb 2024 08:48:04 +0100 Subject: [PATCH 16/17] better conditions --- .github/workflows/doc.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 363a170a6..03c5cffeb 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -58,7 +58,7 @@ jobs: TX_TOKEN: ${{ secrets.TX_TOKEN }} - name: Pull translations from Transifex - if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'opengisch/QgisModelBaker' && github.actor != 'dependabot[bot]' }} + if: contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) || ${{ github.event_name == 'pull_request' && github.repository == 'opengisch/QgisModelBaker' }} run: | ./tx pull --translations --all --minimum-perc 10 ./tx status @@ -66,7 +66,7 @@ jobs: TX_TOKEN: ${{ secrets.TX_TOKEN }} - name: Translate Mkdocs config - if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'opengisch/QgisModelBaker' && github.actor != 'dependabot[bot]' }} + if: contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) || ${{ github.event_name == 'pull_request' && github.repository == 'opengisch/QgisModelBaker' }} run: | ./scripts/mkdocs_tx.py -s en update_config ./scripts/mkdocs_tx_commit.sh @@ -84,5 +84,5 @@ jobs: if-no-files-found: error - name: Deploy to GitHub Pages - if: ${{ github.event_name != 'pull_request' }} + if: contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) run: mkdocs gh-deploy --force From 6d78685b37d71b085d79e1c4a15da2f89a2fbc9c Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Fri, 23 Feb 2024 10:32:14 +0100 Subject: [PATCH 17/17] small script improvements from review --- docs/scripts/mkdocs_tx.py | 44 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/docs/scripts/mkdocs_tx.py b/docs/scripts/mkdocs_tx.py index 47797fe65..0f060975b 100755 --- a/docs/scripts/mkdocs_tx.py +++ b/docs/scripts/mkdocs_tx.py @@ -18,7 +18,7 @@ def read_config(file_path: str): return yaml.load(f) -def nav_config(config): +def nav_config(config) -> dict: _nav_config = {} def add_nav_entry(title, content): @@ -36,31 +36,31 @@ def add_nav_entry(title, content): return _nav_config -def get_site_description(config, source_language): - site_description = None +def site_description(config, source_language) -> str: + _site_description = None found = 0 try: - site_description = config["site_description"] + _site_description = config["site_description"] found += 1 except KeyError: pass try: for plugin in config["plugins"]: - if type(plugin) != str and "i18n" in plugin: - for lang in plugin["i18n"]["languages"]: - ltx = lang["locale"] - if ltx == source_language: - site_description = lang["site_description"] + if not isinstance(plugin, str) and "i18n" in plugin: + for lang_info in plugin["i18n"]["languages"]: + lang = lang_info["locale"] + if lang == source_language: + _site_description = lang_info["site_description"] found += 1 except KeyError: pass if not found: print("No site description found") - elif found > 1 and tx_cfg["site_description"] != config["site_description"]: + elif found > 1 and _site_description != config["site_description"]: print("ERROR: site description found twice and different") assert False - return site_description + return _site_description def create_translation_source(config_path, source_path, source_language): @@ -68,7 +68,7 @@ def create_translation_source(config_path, source_path, source_language): tx_cfg = { "nav": nav_config(config), - "site_description": get_site_description(config, source_language), + "site_description": site_description(config, source_language), } try: @@ -92,15 +92,15 @@ def update_config(config_path, source_path, source_language): for plugin in config["plugins"]: if type(plugin) != str and "i18n" in plugin: found = True - for lang in plugin["i18n"]["languages"]: - ltx = lang["locale"] - print(f"language found: '{ltx}'") + for lang_info in plugin["i18n"]["languages"]: + lang = lang_info["locale"] + print(f"language found: '{lang}'") - if ltx == source_language: + if lang == source_language: print("skipping source language") continue - tx_file = f'{source_path.removesuffix(".yml")}.{ltx}.yml' + tx_file = f'{source_path.removesuffix(".yml")}.{lang}.yml' with open(tx_file) as f: yaml = YAML() tx = yaml.load(f) @@ -108,24 +108,24 @@ def update_config(config_path, source_path, source_language): for _title, _translation in tx["nav"].items(): if not _translation: tx["nav"][_title] = _title - lang["nav_translations"] = tx["nav"] + lang_info["nav_translations"] = tx["nav"] try: - lang["site_description"] = tx[ + lang_info["site_description"] = tx[ "site_description" - ] or get_site_description(config, source_language) + ] or site_description(config, source_language) except KeyError: print("No site description in translation") try: - lang["palette"] = copy.deepcopy(config["theme"]["palette"]) + lang_info["palette"] = copy.deepcopy(config["theme"]["palette"]) i = 0 for palette in tx["theme"]["palette"]: _name = ( palette["toggle"]["name"] or config["theme"]["palette"][i]["toggle"]["name"] ) - lang["palette"][i]["toggle"]["name"] = _name + lang_info["palette"][i]["toggle"]["name"] = _name i += 1 except KeyError: print("No theme/palette/toggle/name in translation")