#!/bin/bash set -e APP_DIR="steam-gift-manager" TRANSLATION_DIR="$APP_DIR/translations" LANGS=("de" "en") # check jq if ! command -v jq &>/dev/null; then echo "❌ jq is required. Install with: sudo apt-get install jq" exit 1 fi echo -e "\n\033[1;32m✅ Extracting translations...\033[0m" # 1. create json files mkdir -p "$TRANSLATION_DIR" for lang in "${LANGS[@]}"; do file="$TRANSLATION_DIR/$lang.json" [ -f "$file" ] || echo "{}" > "$file" done # 2. extract all strings STRINGS=$(grep -rhoP "_\(\s*['\"]((?:[^']|'[^'])*?)['\"]\s*[,)]" \ "$APP_DIR/templates" "$APP_DIR/app.py" | \ sed -E "s/_\(\s*['\"](.+?)['\"]\s*[,)]/\1/" | sort | uniq) # 3. put da keys in da json for lang in "${LANGS[@]}"; do file="$TRANSLATION_DIR/$lang.json" tmp="$file.tmp" jq --argjson keys "$(echo "$STRINGS" | jq -R . | jq -s .)" \ 'reduce $keys[] as $k (.; .[$k] = (.[$k] // ""))' "$file" > "$tmp" mv "$tmp" "$file" done echo -e "\n\033[1;32m✅ Done! Translation keys added.\033[0m"