scripts/sync-strings.sh

design-themes-widgets
orgstar/scripts/sync-strings.sh history · blame · raw

43 lines · 2744 bytes · executable

 1#!/bin/sh
 2# Brings l10n/Localizable.xcstrings and l10n/DeveloperID.xcstrings (the strings with that table,
 3# which only the Developer ID Mac app shows) up to date with the strings the apps show: builds the Mac, Mac
 4# App Store and iOS targets with SWIFT_EMIT_LOC_STRINGS and syncs the catalog from their .stringsdata
 5# files.
 6# New strings are added, ones no longer used are marked stale; translations are kept.
 7# Command titles come from Sources/OrgApp/CommandTitles.swift, which CommandTitleTests keeps current.
 8set -eu
 9
10cd "$(dirname "$0")/.."
11catalog=l10n/Localizable.xcstrings
12mac=.build/loc-mac
13ios=.build/loc-ios
14mas=.build/loc-mas
15
16for scheme in Orgstar OrgstarWidgets; do
17    xcodebuild -scheme "$scheme" -destination 'platform=macOS' -derivedDataPath "$mac" build -quiet SWIFT_EMIT_LOC_STRINGS=YES
18done
19# The App Store targets compile Sources/Orgstar and Sources/OrgstarWidgets with APPSTORE, which
20# shows strings the SwiftPM schemes don't.
21xcodebuild -project ios/Orgstar.xcodeproj -scheme 'Orgstar macOS' -destination 'generic/platform=macOS' -derivedDataPath "$mas" \
22    build -quiet SWIFT_EMIT_LOC_STRINGS=YES CODE_SIGNING_ALLOWED=NO
23for scheme in OrgstarMobile OrgstarShare OrgstarWidgets; do
24    xcodebuild -scheme "$scheme" -destination 'generic/platform=iOS Simulator' -derivedDataPath "$ios" build -quiet SWIFT_EMIT_LOC_STRINGS=YES
25done
26for scheme in OrgstarWatch OrgstarWatchWidgets; do
27    xcodebuild -scheme "$scheme" -destination 'generic/platform=watchOS Simulator' -derivedDataPath "$ios" build -quiet SWIFT_EMIT_LOC_STRINGS=YES
28done
29
30[ -f "$catalog" ] || printf '{\n  "sourceLanguage" : "en",\n  "strings" : {\n\n  },\n  "version" : "1.0"\n}\n' > "$catalog"
31find "$mac" "$ios" -path '*/arm64/*' -name '*.stringsdata' \
32    | grep -E '/(Orgstar|OrgstarMobile|OrgstarWidgets|OrgstarShare|OrgstarWatch|OrgstarWatchWidgets)-p\.build/|/(OrgApp|OrgPresentation|OrgEditorAppKit)-t?\.build/' \
33    > "$mac/stringsdata.txt"
34find "$mas" -path '*/arm64/*' -name '*.stringsdata' | grep -E '/(Orgstar macOS|OrgstarWidgets)\.build/' >> "$mac/stringsdata.txt"
35# The App Store target's folder name has a space, so the list is read a line at a time.
36set --
37while IFS= read -r file; do set -- "$@" "$file"; done < "$mac/stringsdata.txt"
38for catalog in "$catalog" l10n/DeveloperID.xcstrings; do
39    xcrun xcstringstool sync "$catalog" --stringsdata "$@"
40    # xcstringstool writes its own spacing; the committed catalog is Python's sorted JSON.
41    python3 -c "import json, sys; p = sys.argv[1]; d = json.load(open(p)); open(p, 'w').write(json.dumps(d, indent=2, ensure_ascii=False, sort_keys=True) + '\n')" "$catalog"
42    echo "$(python3 -c "import json; print(len(json.load(open('$catalog'))['strings']))") strings in $catalog"
43done