Skip to content

Commit

Permalink
remove unused site_description + update script
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Feb 19, 2024
1 parent 23a41c4 commit bba7d79
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
2 changes: 0 additions & 2 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
47 changes: 43 additions & 4 deletions docs/scripts/mkdocs_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": []}
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit bba7d79

Please sign in to comment.