aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2020-08-16 12:06:29 -0300
committerEuAndreh <eu@euandre.org>2020-08-16 12:07:41 -0300
commitcc0f754b0f670b0e498a85ddcc37d9282c206264 (patch)
tree2c7010e0f2cebc52072c24e4eb784abfdf508553 /scripts
parentscripts/assert-content.sh: Add USAGE text (diff)
downloadeuandre.org-cc0f754b0f670b0e498a85ddcc37d9282c206264.tar.gz
euandre.org-cc0f754b0f670b0e498a85ddcc37d9282c206264.tar.xz
Add scripts/missing-translations.sh
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/missing-translations.sh61
1 files changed, 61 insertions, 0 deletions
diff --git a/scripts/missing-translations.sh b/scripts/missing-translations.sh
new file mode 100755
index 0000000..699c6dd
--- /dev/null
+++ b/scripts/missing-translations.sh
@@ -0,0 +1,61 @@
+#!/usr/bin/env bash
+set -Eeuo pipefail
+
+end="\033[0m"
+red="\033[0;31m"
+red() { echo -e "${red}${1}${end}"; }
+
+JSON="${1:-}"
+[[ -z "${JSON}" ]] && {
+ red 'Missing input JSON file.'
+ cat <<EOF
+Usage:
+ $0 <SITE_JSON_PATH>
+
+ Arguments
+ SITE_JSON_PATH Path to the site.json file which contains data and metadata about pages of the site.
+
+Examples:
+ $0 _site/site.json
+ $0 result/site.json
+ $0 \$(nix-build -A subtasks.docs)/site.json
+EOF
+ exit 2
+}
+
+get-ref() {
+ echo "${1}" | base64 --decode | jq -r .ref
+}
+
+get-lang() {
+ echo "${1}" | base64 --decode | jq -r .lang
+}
+
+declare -A IDENTS
+declare -A ALL_REFS
+accumulate-translation-identifiers() {
+ SELECTOR="${1}"
+ for page in $(jq -r "${SELECTOR} | @base64" "${JSON}"); do
+ REF="$(get-ref "$page")"
+ LANG="$(get-lang "$page")"
+ if [[ -n "${REF}" ]]; then
+ ALL_REFS["${REF}"]=1
+ IDENTS["${REF}:${LANG}"]=1
+ fi
+ done
+}
+
+accumulate-translation-identifiers '.posts[]'
+accumulate-translation-identifiers '.pages[]'
+accumulate-translation-identifiers '.tils[]'
+
+LANGS=(en pt fr)
+
+for ref in "${!ALL_REFS[@]}"; do
+ REF="$(cut -d: -f1 <(echo "${ref}"))"
+ for lang in "${LANGS[@]}"; do
+ if [[ "${IDENTS[${ref}:${lang}]:-}" != 1 ]]; then
+ echo "ref '${ref}' is missing language '${lang}'."
+ fi
+ done
+done