diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 85622aa..116d363 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -56,3 +56,8 @@ entry: pre_commit_hooks/main.sh remove-category-json language: script types: [json] +- id: check-folder-structure + name: Ensure same folder structure between translations + entry: pre_commit_hooks/main.sh check-folder-structure + language: script + types_or: [file, symlink] diff --git a/README.md b/README.md index b70fc40..fc16ccb 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ Please refer to `pre-commit` documentation about [developing hooks interactively In short, run the following command in `radxa-doc/documentation` project folder: ```bash -pre-commit try-repo ../pre-commit-hooks --verbose --all-files -pre-commit try-repo ../pre-commit-hooks --verbose --all-files --hook-stage manual +pre-commit try-repo --verbose --all-files ../pre-commit-hooks +pre-commit try-repo --verbose --all-files --hook-stage manual ../pre-commit-hooks +pre-commit try-repo --verbose --all-files ../pre-commit-hooks check-folder-structure ``` diff --git a/pre_commit_hooks/check-folder-structure.sh b/pre_commit_hooks/check-folder-structure.sh new file mode 100755 index 0000000..6ffdb6b --- /dev/null +++ b/pre_commit_hooks/check-folder-structure.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +check() { + local ret=0 + + # I18n folder structure should mirror each other + if [[ "$1" == docs/* ]] && [[ ! -e "i18n/en/docusaurus-plugin-content-docs/current/${1#docs/}" ]] + then + ret=1 + echo "$1: missing English translation." >&2 + elif [[ "$1" == i18n/en/docusaurus-plugin-content-docs/current/* ]] && [[ ! -e "docs/${1#i18n/en/docusaurus-plugin-content-docs/current/}" ]] + then + ret=1 + echo "$1: missing Chinese translation." >&2 + fi + + return $ret +}