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