-
Notifications
You must be signed in to change notification settings - Fork 434
/
sync-translations.sh
executable file
·80 lines (78 loc) · 2.98 KB
/
sync-translations.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
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
#!/bin/bash
set -e
curl -Lo - https://crowdin.com/backend/download/project/wireguard.zip | bsdtar -C Sources/WireGuardApp -x -f - --strip-components 3 wireguard-apple
find Sources/WireGuardApp/*.lproj -type f -empty -delete
find Sources/WireGuardApp/*.lproj -type d -empty -delete
declare -A ALL_BASE
while read -r key eq rest; do
[[ $key == \"* && $key == *\" && $eq == = ]] || continue
ALL_BASE["$key"]="$rest"
done < Sources/WireGuardApp/Base.lproj/Localizable.strings
for f in Sources/WireGuardApp/*.lproj/Localizable.strings; do
unset FOUND
declare -A FOUND
while read -r key eq _; do
[[ $key == \"* && $key == *\" && $eq == = ]] || continue
FOUND["$key"]=1
done < "$f"
for key in "${!ALL_BASE[@]}"; do
[[ ${FOUND["$key"]} -eq 1 ]] && continue
echo "$key = ${ALL_BASE["$key"]}"
done >> "$f"
done < Sources/WireGuardApp/Base.lproj/Localizable.strings
git add Sources/WireGuardApp/*.lproj
declare -A LOCALE_MAP
[[ $(< WireGuard.xcodeproj/project.pbxproj) =~ [[:space:]]([0-9A-F]{24})\ /\*\ Base\ \*/\ =\ [^$'\n']*Base\.lproj/Localizable\.strings ]]
base_id="${BASH_REMATCH[1]:0:16}"
idx=$(( "0x${BASH_REMATCH[1]:16}" ))
while read -r filename; do
l="$(basename "$(dirname "$filename")" .lproj)"
[[ $l == Base ]] && continue
((++idx))
LOCALE_MAP["$l"]="$(printf '%s%08X' "$base_id" $idx)"
done < <(find Sources/WireGuardApp -name Localizable.strings -type f)
inkr=0 inls=0 inlsc=0
while IFS= read -r line; do
if [[ $line == *"name = Base; path = Sources/WireGuardApp/Base.lproj/Localizable.strings"* ]]; then
echo "$line"
for l in "${!LOCALE_MAP[@]}"; do
printf '\t\t%s /* %s */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = %s; path = Sources/WireGuardApp/%s.lproj/Localizable.strings; sourceTree = "<group>"; };\n' "${LOCALE_MAP["$l"]}" "$l" "$l" "$l"
done
elif [[ $line == *"; path = Sources/WireGuardApp/"*".lproj/Localizable.strings"* ]]; then
continue
elif [[ $line == *"knownRegions = ("* ]]; then
echo "$line"
printf '\t\t\t\tBase,\n\t\t\t\ten,\n'
for l in "${!LOCALE_MAP[@]}"; do
[[ $l == *-* ]] && l="\"$l\""
printf '\t\t\t\t%s,\n' "$l"
done
inkr=1
elif [[ $inkr -eq 1 && $line == *");"* ]]; then
echo "$line"
inkr=0
elif [[ $inkr -eq 1 ]]; then
continue
elif [[ $inls -eq 0 && $line == *"/* Localizable.strings */ = {"* ]]; then
echo "$line"
inls=1
elif [[ $inls -eq 1 && $inlsc -eq 0 && $line == *"children = ("* ]]; then
echo "$line"
inlsc=1
for l in "${!LOCALE_MAP[@]}"; do
printf '\t\t\t\t%s /* %s */,\n' "${LOCALE_MAP["$l"]}" "$l"
done
elif [[ $inls -eq 1 && $inlsc -eq 1 && $line == *");"* ]]; then
echo "$line"
inlsc=0
elif [[ $inls -eq 1 && $inlsc -eq 0 && $line == *"};"* ]]; then
echo "$line"
inls=0
elif [[ $inls -eq 1 && $inlsc -eq 1 && $line != *" Base "* ]]; then
continue
else
echo "$line"
fi
done < WireGuard.xcodeproj/project.pbxproj > WireGuard.xcodeproj/project.pbxproj.new
mv WireGuard.xcodeproj/project.pbxproj.new WireGuard.xcodeproj/project.pbxproj
git add WireGuard.xcodeproj/project.pbxproj