docs: Mkdocs i18n support (#5072)

Signed-off-by: Yifei DIng <yifeiding@protonmail.com>
This commit is contained in:
Yifei Ding
2022-02-14 08:29:41 -08:00
committed by GitHub
parent f0241d7dec
commit 61329049a6
6 changed files with 60 additions and 22 deletions

View File

@@ -0,0 +1,30 @@
#!/bin/bash
# Modify the file structure before running mkdocs
# This is a make shift script before the current structure of
# Klipper-translations can be directly utilized by mkdocs
# Usage: pre-mkdocs.sh <lang_directory_name> <target_lang_name>
#git clone --depth 1 https://github.com/Klipper3d/klipper-translations
while IFS="," read dirname langname langdesc note; do
# move and rename markdown files
local_dir="klipper-translations/docs/locales/$dirname"
echo "Moving $dirname to $langname"
for file in "$local_dir"/*.md; do
mdfilename="${file/$local_dir\//}"
mv "$file" "./docs/${mdfilename//.md/.${langname}.md}"
done
# manually replace index.md if a manual-index.md exist
manual_index="./docs/manual-index.$langname.md"
if [[ -f "$manual_index" ]];then
mv "$manual_index" "./docs/index.${langname}.md"
echo "replaced index.${langname}.md with $manual_index"
else
echo "Manually translated index file for $dirname not found!"
fi
# add to translations.yml
echo " ${langname}: ${langdesc}" >> ./docs/_klipper3d/translations.yml
done < <(egrep -v '^ *(#|$)' ./klipper-translations/active_translations | tail -n +2)

View File

@@ -6,3 +6,4 @@ mkdocs-exclude==1.0.2
mdx-truly-sane-lists==1.2
mdx-breakless-lists==1.0.1
py-gfm==1.0.2
mkdocs-static-i18n=0.30

View File

@@ -8,6 +8,7 @@ edit_uri: blob/master/docs/
use_directory_urls: False
docs_dir: '../'
site_dir: '../../site/'
INHERIT: translations.yml
# Markdown document translation settings
markdown_extensions:
@@ -19,13 +20,12 @@ markdown_extensions:
- mdx_truly_sane_lists
- mdx_breakless_lists
plugins:
- search
- mkdocs-simple-hooks:
hooks:
on_page_markdown: "docs._klipper3d.mkdocs_hooks:transform"
- exclude:
glob:
- README.md
search: {}
mkdocs-simple-hooks:
hooks:
on_page_markdown: "docs._klipper3d.mkdocs_hooks:transform"
exclude:
glob: "README.md"
# Website layout configuration (using mkdocs-material theme)
theme:

View File

@@ -0,0 +1,5 @@
plugins:
i18n:
default_language: en
languages:
en: English