diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-12-11 12:38:24 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-12-11 12:39:43 +0100 |
commit | 8fd4883d7e4648c23c299e31c2c78e1cd77f9c5f (patch) | |
tree | 47e3d034335eb96b2e5796d3bda8edbca1ab3dea /sync-translations.sh | |
parent | WireGuardKit: Let wireguard-go backend run in offline on macOS (diff) | |
download | wireguard-apple-8fd4883d7e4648c23c299e31c2c78e1cd77f9c5f.tar.xz wireguard-apple-8fd4883d7e4648c23c299e31c2c78e1cd77f9c5f.zip |
WireGuardApp: modify xcodeproj when syncing translations
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'sync-translations.sh')
-rwxr-xr-x | sync-translations.sh | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/sync-translations.sh b/sync-translations.sh index b2d72eb..f789010 100755 --- a/sync-translations.sh +++ b/sync-translations.sh @@ -1,6 +1,59 @@ #!/bin/bash -set -ex +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 |