new folder structure / add de translation
This commit is contained in:
parent
8aba6f5129
commit
4a0a5bac3f
35 changed files with 696 additions and 1124 deletions
51
translate.sh
51
translate.sh
|
@ -1,28 +1,41 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
cd "$(dirname "$0")/steam-gift-manager"
|
||||
APP_DIR="steam-gift-manager"
|
||||
TRANSLATION_DIR="$APP_DIR/translations"
|
||||
LANGS=("de" "en")
|
||||
|
||||
declare -A locales=(
|
||||
["de"]="de"
|
||||
["en"]="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
|
||||
|
||||
# create POT-file
|
||||
docker-compose exec steam-manager pybabel extract -F babel.cfg -o translations/messages.pot .
|
||||
|
||||
# Check for each language and initialize if necessary
|
||||
for lang in "${!locales[@]}"; do
|
||||
if [ ! -f "translations/${locales[$lang]}/LC_MESSAGES/messages.po" ]; then
|
||||
docker-compose exec steam-manager pybabel init \
|
||||
-i translations/messages.pot \
|
||||
-d translations \
|
||||
-l "${locales[$lang]}"
|
||||
# 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
|
||||
|
||||
# Update and compile translations
|
||||
docker-compose exec steam-manager pybabel update -i translations/messages.pot -d translations
|
||||
docker-compose exec steam-manager pybabel compile -d translations
|
||||
# 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)
|
||||
|
||||
echo "✅ Translations updated!"
|
||||
# 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!"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue