]>
Commit | Line | Data |
---|---|---|
54e3333b | 1 | #!/bin/bash |
8fd4883d | 2 | set -e |
54e3333b JD |
3 | curl -Lo - https://crowdin.com/backend/download/project/wireguard.zip | bsdtar -C Sources/WireGuardApp -x -f - --strip-components 3 wireguard-apple |
4 | find Sources/WireGuardApp/*.lproj -type f -empty -delete | |
5 | find Sources/WireGuardApp/*.lproj -type d -empty -delete | |
49b7d083 JD |
6 | declare -A ALL_BASE |
7 | while read -r key eq rest; do | |
8 | [[ $key == \"* && $key == *\" && $eq == = ]] || continue | |
9 | ALL_BASE["$key"]="$rest" | |
10 | done < Sources/WireGuardApp/Base.lproj/Localizable.strings | |
11 | for f in Sources/WireGuardApp/*.lproj/Localizable.strings; do | |
12 | unset FOUND | |
13 | declare -A FOUND | |
14 | while read -r key eq _; do | |
15 | [[ $key == \"* && $key == *\" && $eq == = ]] || continue | |
16 | FOUND["$key"]=1 | |
17 | done < "$f" | |
18 | for key in "${!ALL_BASE[@]}"; do | |
19 | [[ ${FOUND["$key"]} -eq 1 ]] && continue | |
20 | echo "$key = ${ALL_BASE["$key"]}" | |
21 | done >> "$f" | |
22 | done < Sources/WireGuardApp/Base.lproj/Localizable.strings | |
54e3333b | 23 | git add Sources/WireGuardApp/*.lproj |
8fd4883d JD |
24 | |
25 | declare -A LOCALE_MAP | |
a613fec2 | 26 | [[ $(< WireGuard.xcodeproj/project.pbxproj) =~ [[:space:]]([0-9A-F]{24})\ /\*\ Base\ \*/\ =\ [^$'\n']*Base\.lproj/Localizable\.strings ]] |
403ee636 JD |
27 | base_id="${BASH_REMATCH[1]:0:16}" |
28 | idx=$(( "0x${BASH_REMATCH[1]:16}" )) | |
8fd4883d JD |
29 | while read -r filename; do |
30 | l="$(basename "$(dirname "$filename")" .lproj)" | |
31 | [[ $l == Base ]] && continue | |
403ee636 JD |
32 | ((++idx)) |
33 | LOCALE_MAP["$l"]="$(printf '%s%08X' "$base_id" $idx)" | |
8fd4883d JD |
34 | done < <(find Sources/WireGuardApp -name Localizable.strings -type f) |
35 | ||
36 | inkr=0 inls=0 inlsc=0 | |
37 | while IFS= read -r line; do | |
38 | if [[ $line == *"name = Base; path = Sources/WireGuardApp/Base.lproj/Localizable.strings"* ]]; then | |
39 | echo "$line" | |
40 | for l in "${!LOCALE_MAP[@]}"; do | |
41 | 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" | |
42 | done | |
43 | elif [[ $line == *"; path = Sources/WireGuardApp/"*".lproj/Localizable.strings"* ]]; then | |
44 | continue | |
45 | elif [[ $line == *"knownRegions = ("* ]]; then | |
46 | echo "$line" | |
47 | printf '\t\t\t\tBase,\n\t\t\t\ten,\n' | |
48 | for l in "${!LOCALE_MAP[@]}"; do | |
403ee636 | 49 | [[ $l == *-* ]] && l="\"$l\"" |
8fd4883d JD |
50 | printf '\t\t\t\t%s,\n' "$l" |
51 | done | |
52 | inkr=1 | |
53 | elif [[ $inkr -eq 1 && $line == *");"* ]]; then | |
54 | echo "$line" | |
55 | inkr=0 | |
56 | elif [[ $inkr -eq 1 ]]; then | |
57 | continue | |
58 | elif [[ $inls -eq 0 && $line == *"/* Localizable.strings */ = {"* ]]; then | |
59 | echo "$line" | |
60 | inls=1 | |
61 | elif [[ $inls -eq 1 && $inlsc -eq 0 && $line == *"children = ("* ]]; then | |
62 | echo "$line" | |
63 | inlsc=1 | |
64 | for l in "${!LOCALE_MAP[@]}"; do | |
65 | printf '\t\t\t\t%s /* %s */,\n' "${LOCALE_MAP["$l"]}" "$l" | |
66 | done | |
67 | elif [[ $inls -eq 1 && $inlsc -eq 1 && $line == *");"* ]]; then | |
68 | echo "$line" | |
69 | inlsc=0 | |
70 | elif [[ $inls -eq 1 && $inlsc -eq 0 && $line == *"};"* ]]; then | |
71 | echo "$line" | |
72 | inls=0 | |
73 | elif [[ $inls -eq 1 && $inlsc -eq 1 && $line != *" Base "* ]]; then | |
74 | continue | |
75 | else | |
76 | echo "$line" | |
77 | fi | |
78 | done < WireGuard.xcodeproj/project.pbxproj > WireGuard.xcodeproj/project.pbxproj.new | |
79 | mv WireGuard.xcodeproj/project.pbxproj.new WireGuard.xcodeproj/project.pbxproj | |
80 | git add WireGuard.xcodeproj/project.pbxproj |