scripts/sync-strings.sh

29 lines · 1689 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.
 5# Command titles come from Sources/OrgApp/CommandTitles.swift, which CommandTitleTests keeps current.
 6set -eu
 7
 8cd "$(dirname "$0")/.."
 9catalog=l10n/Localizable.xcstrings
10mac=.build/loc-mac
11ios=.build/loc-ios
12
13for scheme in Orgstar OrgstarWidgets; do
14    xcodebuild -scheme "$scheme" -destination 'platform=macOS' -derivedDataPath "$mac" build -quiet SWIFT_EMIT_LOC_STRINGS=YES
15done
16for scheme in OrgstarMobile OrgstarShare OrgstarWidgets; do
17    xcodebuild -scheme "$scheme" -destination 'generic/platform=iOS Simulator' -derivedDataPath "$ios" build -quiet SWIFT_EMIT_LOC_STRINGS=YES
18done
19for scheme in OrgstarWatch OrgstarWatchWidgets; do
20    xcodebuild -scheme "$scheme" -destination 'generic/platform=watchOS Simulator' -derivedDataPath "$ios" build -quiet SWIFT_EMIT_LOC_STRINGS=YES
21done
22
23[ -f "$catalog" ] || printf '{\n  "sourceLanguage" : "en",\n  "strings" : {\n\n  },\n  "version" : "1.0"\n}\n' > "$catalog"
24find "$mac" "$ios" -path '*/arm64/*' -name '*.stringsdata' \
25    | grep -E '/(Orgstar|OrgstarMobile|OrgstarWidgets|OrgstarShare|OrgstarWatch|OrgstarWatchWidgets)-p\.build/|/(OrgApp|OrgPresentation|OrgEditorAppKit)-t?\.build/' \
26    > "$mac/stringsdata.txt"
27# shellcheck disable=SC2046
28xcrun xcstringstool sync "$catalog" --stringsdata $(tr '\n' ' ' < "$mac/stringsdata.txt")
29echo "$(python3 -c "import json; print(len(json.load(open('$catalog'))['strings']))") strings in $catalog"