https://dev.kronoz.win/r/marzneshin.git
1#!/bin/bash
2
3jq_pathify() {
4 local key="$1"
5 local jq_path=""
6 IFS='.' read -ra parts <<< "$key"
7 for part in "${parts[@]}"; do
8 if [[ "$part" =~ ^[a-zA-Z0-9_]+$ ]]; then
9 jq_path+=".${part}"
10 else
11 jq_path+="[\"$part\"]"
12 fi
13 done
14 echo "$jq_path"
15}
16
17json_file=$1
18tkeys_file=$(mktemp)
19grep --exclude-dir={node_modules,dist} -orPh "\Wt\([\"']\K[\w.-]+(?=[\"'])" ./dashboard | sort | uniq > $tkeys_file
20
21missingkc=0
22while IFS= read -r key; do
23 # jq_query=".$key"
24 jq_query=$(jq_pathify $key)
25 if [[ "$jq_query" != .* ]]; then
26 jq_query=".$jq_query"
27 fi
28 jq -e "$jq_query // empty" "$json_file" > /dev/null || { echo "translation lacks $key"; ((missingkc++)); }
29done < $tkeys_file
30
31
32extrakeys=$(jq -r 'paths(scalars) | join(".")' $json_file | grep -vxFf $tkeys_file)
33
34while IFS= read -r line; do
35 echo "found extra key $line"
36done <<< "$extrakeys"
37
38extrakc=$(wc -l <<< $extrakeys)
39
40
41if [[ $extrakc -gt 0 || $missingkc -gt 0 ]]; then
42 echo "Check failed. missing keys: $missingkc, extra keys: $extrakc"
43 exit 1
44else
45 echo "Check passed. No extra/missing keys."
46fi