#!/bin/bash set -e APP_DIR="steam-gift-manager" TRANSLATION_DIR="$APP_DIR/translations" LANGS=("de" "en") # Prüfe jq if ! command -v jq &>/dev/null; then echo "❌ jq is required. Install with: sudo apt-get install jq" exit 1 fi # 1. Lege JSON-Dateien an, falls sie fehlen for lang in "${LANGS[@]}"; do file="$TRANSLATION_DIR/$lang.json" if [ ! -f "$file" ]; then echo "{}" > "$file" echo "Created $file" fi done # 2. Extrahiere alle zu übersetzenden Strings STRINGS=$(grep -rhoP "_\(\s*['\"](.+?)['\"]\s*\)" \ "$APP_DIR/templates" "$APP_DIR/app.py" | \ sed -E "s/_\(\s*['\"](.+?)['\"]\s*\)/\1/" | sort | uniq) # 3. Ergänze neue Keys in die JSON-Dateien for lang in "${LANGS[@]}"; do file="$TRANSLATION_DIR/$lang.json" tmp="$file.tmp" cp "$file" "$tmp" while IFS= read -r key; do if ! jq -e --arg k "$key" 'has($k)' "$tmp" >/dev/null; then jq --arg k "$key" '. + {($k): ""}' "$tmp" > "$tmp.new" && mv "$tmp.new" "$tmp" fi done <<< "$STRINGS" mv "$tmp" "$file" echo "Updated $file" done echo "✅ JSON translation files updated. Please enter your translations!"