scripts/sync-strings.sh

28 lines · 1587 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
18for scheme in OrgstarWatch OrgstarWatchWidgets; do
19    xcodebuild -scheme "$scheme" -destination 'generic/platform=watchOS Simulator' -derivedDataPath "$ios" build -quiet SWIFT_EMIT_LOC_STRINGS=YES
20done
21
22[ -f "$catalog" ] || printf '{\n  "sourceLanguage" : "en",\n  "strings" : {\n\n  },\n  "version" : "1.0"\n}\n' > "$catalog"
23find "$mac" "$ios" -path '*/arm64/*' -name '*.stringsdata' \
24    | grep -E '/(Orgstar|OrgstarMobile|OrgstarWidgets|OrgstarShare|OrgstarWatch|OrgstarWatchWidgets)-p\.build/|/(OrgApp|OrgPresentation|OrgEditorAppKit)-t?\.build/' \
25    > "$mac/stringsdata.txt"
26# shellcheck disable=SC2046
27xcrun xcstringstool sync "$catalog" --stringsdata $(tr '\n' ' ' < "$mac/stringsdata.txt")
28echo "$(python3 -c "import json; print(len(json.load(open('$catalog'))['strings']))") strings in $catalog"