aboutsummaryrefslogtreecommitdiffstats
path: root/sync-translations.sh
blob: f789010125471f45e5ec9ef155e8946ef14c571f (plain) (blame)
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
#!/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
git add Sources/WireGuardApp/*.lproj

declare -A LOCALE_MAP
while read -r filename; do
	l="$(basename "$(dirname "$filename")" .lproj)"
	[[ $l == Base ]] && continue
	read -r -n 24 hex < <(LC_ALL=C tr -dc "A-F0-9" < /dev/urandom)
	LOCALE_MAP["$l"]="$hex"
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
			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