scripts/sync-strings.sh

213799f3f0792831bdbd707d1f85cb19b614f39f
orgstar/scripts/sync-strings.sh

40 lines · 2560 bytes · executable

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

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form