make translate.sh more robust

This commit is contained in:
nocci 2025-05-02 12:07:27 +02:00
parent 3b93b14e29
commit f260da3594
1 changed files with 22 additions and 17 deletions

View File

@ -885,29 +885,34 @@ set -e
cd "$(dirname "$0")/steam-gift-manager"
declare -A locales=(
["de"]="de"
["en"]="en"
)
declare -a locales=("de" "en")
# create POT-file
docker-compose exec steam-manager pybabel extract -F babel.cfg -o translations/messages.pot .
docker-compose run --rm 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]}"
for lang in "${locales[@]}"; do
po_path="translations/${lang}/LC_MESSAGES/messages.po"
if [ -f "$po_path" ]; then
encoding=$(file -i "$po_path" | grep -Po 'charset=\K.+')
if [[ "$encoding" != "utf-8" ]]; then
echo "Konvertiere $po_path von $encoding nach UTF-8"
iconv -f "$encoding" -t UTF-8 "$po_path" > "$po_path.utf8"
mv "$po_path.utf8" "$po_path"
fi
fi
docker-compose run --rm steam-manager pybabel update \
-i translations/messages.pot \
-d translations \
-l "$lang" \
--previous
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
docker-compose run --rm steam-manager pybabel compile -d translations
echo "✅ Setup and/or update translations done! YOLO"
echo "✅ Translations updated!"
SCRIPT_END
chmod +x ../translate.sh