-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-langs.sh
executable file
·38 lines (33 loc) · 1011 Bytes
/
build-langs.sh
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
#!/bin/bash
if ! command -v jq &> /dev/null; then
echo "jq is not installed, please install jq first."
exit 1
fi
output_folder="./gl-router-sdk-languages"
rm -rf "$output_folder"
rm -rf "$output_folder.zip"
mkdir -p "$output_folder"
merge_lang() {
merged_json=""
for path in $(find "./" -type f -regex ".*/\(en\)\.json$" -print0 | xargs -0 -n1 dirname); do
files=$(ls "$path"/*.json)
for file in $files; do
filename=$(basename "$file" .json)
if [ "$filename" == "zh_Hant" ]; then
filename="zh-tw"
fi
if [ "$filename" == "zh_Hans" ]; then
filename="zh-cn"
fi
output_file="$output_folder/release.$filename.json"
if [ -f "$output_file" ]; then
merged_json=$(jq -s 'reduce .[] as $item ({}; . * $item)' "$output_file" "$file")
else
merged_json=$(jq -s add "$file")
fi
echo "$(jq -c '.' <<< "$merged_json")" > "$output_file"
done
done
zip -r "$output_folder.zip" "$output_folder"
}
merge_lang