-
Notifications
You must be signed in to change notification settings - Fork 3
98 lines (86 loc) · 2.51 KB
/
translations.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
name: Translation
on: push
jobs:
regex-json-verification:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Verify Regex and JSON
run: |
# Run regex verification
source_keys=()
while IFS= read -r match
do
# Extract the desired part from the match using awk
clean_match=$(echo "$match" | awk -F "['\"]" '{print $2}')
source_keys+=("$clean_match")
done < <(grep -r -P -o "(?<=§\()['\"]([\w-]+)['\"]" .)
if [ ${#source_keys[@]} -gt 0 ]
then
echo "Regex pattern found in code."
else
echo "Regex pattern not found."
exit 1
fi
# Verify JSON keys
json_keys=($(jq -r 'keys[]' translations/en.json))
if [ ${#json_keys[@]} -gt 0 ]
then
echo "JSON source found."
else
echo "JSON source not found."
exit 1
fi
#Matching keys
MISMATCH_FOUND=false
for source_key in "${source_keys[@]}"
do
KEY_FOUND=false
for json_key in "${json_keys[@]}"
do
if [ "$json_key" = "$source_key" ]
then
KEY_FOUND=true
break
fi
done
if [ "$KEY_FOUND" = false ]
then
echo "Key ${source_key} is not defined"
MISMATCH_FOUND=true
fi
done
if [ "$MISMATCH_FOUND" = true ]
then
echo "Some asked JSON keys were not found."
exit 1
else
echo "All asked JSON keys were found."
fi
#Inverse matching
UNUSED_KEYS=false
for json_key in "${json_keys[@]}"
do
KEY_FOUND=false
for source_key in "${source_keys[@]}"
do
if [ "$json_key" = "$source_key" ]
then
KEY_FOUND=true
break
fi
done
if [ "$KEY_FOUND" = false ]
then
echo "Key ${json_key} is not used"
UNUSED_KEYS=true
fi
done
if [ "$UNUSED_KEYS" = true ]
then
echo "Some JSON keys were not been used."
exit 1
else
echo "All JSON keys were been used."
fi