-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
195 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,2 @@ | ||
[main] | ||
host = https://www.transifex.com | ||
|
||
[o:opengisch:p:signalo-website:r:documentation_desktop] | ||
file_filter = documentation/desktop.<lang>.md | ||
source_file = documentation/desktop.fr.md | ||
source_lang = fr | ||
type = GITHUBMARKDOWN | ||
|
||
[o:opengisch:p:signalo-website:r:documentation_roadmap] | ||
file_filter = documentation/roadmap.<lang>.md | ||
source_file = documentation/roadmap.fr.md | ||
source_lang = fr | ||
type = GITHUBMARKDOWN | ||
|
||
[o:opengisch:p:signalo-website:r:documentation_mobile] | ||
file_filter = documentation/mobile.<lang>.md | ||
source_file = documentation/mobile.fr.md | ||
source_lang = fr | ||
type = GITHUBMARKDOWN | ||
|
||
[o:opengisch:p:signalo-website:r:documentation_installation] | ||
file_filter = documentation/installation.<lang>.md | ||
source_file = documentation/installation.fr.md | ||
source_lang = fr | ||
type = GITHUBMARKDOWN | ||
|
||
[o:opengisch:p:signalo-website:r:documentation_home] | ||
file_filter = documentation/index.<lang>.md | ||
source_file = documentation/index.fr.md | ||
source_lang = fr | ||
type = GITHUBMARKDOWN | ||
|
||
[o:opengisch:p:signalo-website:r:documentation_datamodel-doc] | ||
file_filter = documentation/datamodel-doc.<lang>.md | ||
source_file = documentation/datamodel-doc.fr.md | ||
source_lang = fr | ||
type = GITHUBMARKDOWN | ||
|
||
[o:opengisch:p:signalo-website:r:documentation_data-model] | ||
file_filter = documentation/data-model.<lang>.md | ||
source_file = documentation/data-model.fr.md | ||
source_lang = fr | ||
type = GITHUBMARKDOWN | ||
|
||
[o:opengisch:p:signalo-website:r:documentation_contribute] | ||
file_filter = documentation/contribute.<lang>.md | ||
source_file = documentation/contribute.fr.md | ||
source_lang = fr | ||
type = GITHUBMARKDOWN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ruamel.yaml==0.18.6 | ||
pre-commit==3.6.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
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) | ||
pre-commit install | ||
pre-commit run --files mkdocs.yml || true | ||
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} | ||
pre-commit install | ||
pre-commit run --files mkdocs.yml || true | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters