1
+ #! /usr/bin/env bash
2
+ #
3
+ # check that all the translations are complete
4
+ #
5
+
6
+ set -o errexit
7
+ set -o nounset
8
+ set -o pipefail
9
+
10
+ SCRIPT_HOME=$( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd)
11
+ REPO_HOME=$( cd " ${SCRIPT_HOME} /.." && pwd)
12
+ MAIN_LANG=en
13
+
14
+ # check if jq is installed
15
+ if ! command -v jq & > /dev/null; then
16
+ echo " ERROR: jq is not installed. try 'apt-get install jq' or 'brew install jq'"
17
+ exit 1
18
+ fi
19
+
20
+ echo " INFO: starting at $( date -u +%Y-%m-%dT%H:%M:%SZ) "
21
+
22
+
23
+ MESSAGE_DIR=" ${REPO_HOME} /messages"
24
+
25
+ MAIN_FILE=" ${MESSAGE_DIR} /${MAIN_LANG} .json"
26
+ if [ ! -f " ${MAIN_FILE} " ]; then
27
+ echo " ERROR: primary translations file not found: \" ${MAIN_FILE} \" "
28
+ exit 2
29
+ fi
30
+ MAIN_KEYS=$( jq -r ' paths(scalars) | join(".")' " ${MAIN_FILE} " | sort)
31
+ echo " INFO: keys in primary translations file: $( echo " ${MAIN_KEYS} " | wc -l) "
32
+
33
+ # get the list of translation files
34
+ FILES=$( find " ${MESSAGE_DIR} " -type f -name ' *.json' )
35
+
36
+ count=0
37
+
38
+ # check if all the translations are complete
39
+ for FILE in ${FILES} ; do
40
+ # get the language code
41
+ LANG=$( basename " ${FILE} " .json)
42
+ if [ " ${LANG} " == " ${MAIN_LANG} " ]; then
43
+ echo " INFO: skipping main language ${LANG} (${FILE} )"
44
+ continue
45
+ fi
46
+
47
+ echo " INFO: checking ${LANG} (${FILE} )"
48
+
49
+ KEYS=$( jq -r ' paths(scalars) | join(".")' " ${FILE} " | sort)
50
+ echo " INFO: keys in ${LANG} translations: $( echo " ${KEYS} " | wc -l) "
51
+
52
+ set +e
53
+ DIFF=$( diff --suppress-common-lines <( echo " ${MAIN_KEYS} " ) <( echo " ${KEYS} " ) | grep -E ' ^[<>]' )
54
+ set -e
55
+ # echo "INFO: diff is \"$DIFF\""
56
+
57
+ if [ -z " ${DIFF} " ]; then
58
+ echo " INFO: ${LANG} translations are complete"
59
+ continue
60
+ fi
61
+
62
+ DELTA=$( echo " ${DIFF} " | wc -l)
63
+ echo " INFO: ${LANG} translations have ${DELTA} missing keys"
64
+ if [ " ${DELTA} " -gt 0 ]; then
65
+ echo " ERROR: ${LANG} translations are incomplete: ${DELTA} missing keys"
66
+ echo " ${DIFF} "
67
+ count=$(( count + 1 ))
68
+ fi
69
+
70
+ done
71
+
72
+ echo " INFO: complete at $( date -u +%Y-%m-%dT%H:%M:%SZ) "
73
+
74
+ if [ " ${count} " -gt 0 ]; then
75
+ echo " ERROR: ${count} translations are incomplete"
76
+ exit 3
77
+ fi
78
+
79
+ echo " INFO: all translations are complete"
0 commit comments