From f260da35944c45a6033b319c814f6ded38cb170b Mon Sep 17 00:00:00 2001 From: nocci Date: Fri, 2 May 2025 12:07:27 +0200 Subject: [PATCH] make translate.sh more robust --- setup.sh | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/setup.sh b/setup.sh index 095acc3..38e8915 100644 --- a/setup.sh +++ b/setup.sh @@ -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