SPB Git

Repository Public

sync-strings.sh 3.0 KB 61 lines shellscript

1#!/usr/bin/env bash2# SP Wallet iOS3# File: Scripts/sync-strings.sh4# Description: Extract every localizable string of the app and of the widget extension into Resources/Localizable.xcstrings.5#              Builds the app for the simulator in its own derived data (build/DerivedData-strings, so a test run using6#              build/DerivedData is not disturbed), collects the *.stringsdata the compiler emitted for the SPWallet and7#              SPWalletWidgets targets (SWIFT_EMIT_LOC_STRINGS) and merges them with xcstringstool. Existing translations8#              are kept; keys that left the source are marked stale; new keys appear untranslated.9#              usage: sync-strings.sh [--no-build] [--keep-stale]10#                --no-build    reuse the .stringsdata of the previous build11#                --keep-stale  do not mark or remove keys that are no longer in the source12#13# Author: Simon-Pierre Boucher14# Contact: contact@spboucher.ai15set -uo pipefail16cd "$(dirname "$0")/.."17DD="build/DerivedData-strings"18CATALOG="Resources/Localizable.xcstrings"19BUILD=120EXTRA=()21for arg in "$@"; do22  case "$arg" in23    --no-build) BUILD=0 ;;24    --keep-stale) EXTRA+=(--skip-marking-strings-stale) ;;25    *) echo "usage: sync-strings.sh [--no-build] [--keep-stale]"; exit 2 ;;26  esac27done28mkdir -p build/logs29if [[ $BUILD -eq 1 ]]; then30  Scripts/build.sh generate || exit 131  if ! xcodebuild -project SPWallet.xcodeproj -scheme SPWallet -configuration Debug -destination "generic/platform=iOS Simulator" \32      -derivedDataPath "$DD" build > build/logs/strings-build.log 2>&1; then33    grep -E "error:|\*\* " build/logs/strings-build.log | sort -u | head -4034    echo "build failed (build/logs/strings-build.log)"; exit 135  fi36fi37# Only the two targets that compile the catalog; one architecture is enough (the strings are the same in each slice).38FILES=()39for target in SPWallet SPWalletWidgets; do40  dir=""41  for arch in arm64 x86_64; do42    candidate="$DD/Build/Intermediates.noindex/SPWallet.build/Debug-iphonesimulator/$target.build/Objects-normal/$arch"43    if [[ -d "$candidate" ]] && compgen -G "$candidate/*.stringsdata" > /dev/null; then dir="$candidate"; break; fi44  done45  [[ -z "$dir" ]] && { echo "no .stringsdata for $target (build first)"; exit 1; }46  while IFS= read -r f; do FILES+=(--stringsdata "$f"); done < <(find "$dir" -name "*.stringsdata" | sort)47done48xcrun xcstringstool sync "$CATALOG" "${FILES[@]}" ${EXTRA[@]+"${EXTRA[@]}"} || exit 149python3 - "$CATALOG" <<'PY'50import json, sys51strings = json.load(open(sys.argv[1], encoding="utf-8"))["strings"]52def english(entry):53    loc = entry.get("localizations", {}).get("en", {})54    return "stringUnit" in loc or "variations" in loc55stale = [k for k, v in strings.items() if v.get("extractionState") == "stale"]56missing = [k for k, v in strings.items() if not english(v)]57print(f"{len(strings)} keys, {len(missing)} without English, {len(stale)} stale")58for k in missing[:40]: print("  untranslated:", k)59for k in stale[:40]: print("  stale:", k)60PY61
Files main
Menu

Theme