scripts/sync-strings.sh
25 lines · 1351 bytes · executable
1#!/bin/sh
2# Brings l10n/Localizable.xcstrings up to date with the strings the apps show: builds the Mac and
3# iOS targets with SWIFT_EMIT_LOC_STRINGS and syncs the catalog from their .stringsdata files.
4# New strings are added, ones no longer used are marked stale; translations are kept.
5set -eu
6
7cd "$(dirname "$0")/.."
8catalog=l10n/Localizable.xcstrings
9mac=.build/loc-mac
10ios=.build/loc-ios
11
12for scheme in Orgstar OrgstarWidgets; do
13 xcodebuild -scheme "$scheme" -destination 'platform=macOS' -derivedDataPath "$mac" build -quiet SWIFT_EMIT_LOC_STRINGS=YES
14done
15for scheme in OrgstarMobile OrgstarShare OrgstarWidgets; do
16 xcodebuild -scheme "$scheme" -destination 'generic/platform=iOS Simulator' -derivedDataPath "$ios" build -quiet SWIFT_EMIT_LOC_STRINGS=YES
17done
18
19[ -f "$catalog" ] || printf '{\n "sourceLanguage" : "en",\n "strings" : {\n\n },\n "version" : "1.0"\n}\n' > "$catalog"
20find "$mac" "$ios" -path '*/arm64/*' -name '*.stringsdata' \
21 | grep -E '/(Orgstar|OrgstarMobile|OrgstarWidgets|OrgstarShare)-p\.build/|/(OrgApp|OrgPresentation|OrgEditorAppKit)-t?\.build/' \
22 > "$mac/stringsdata.txt"
23# shellcheck disable=SC2046
24xcrun xcstringstool sync "$catalog" --stringsdata $(tr '\n' ' ' < "$mac/stringsdata.txt")
25echo "$(python3 -c "import json; print(len(json.load(open('$catalog'))['strings']))") strings in $catalog"