From 3b93b14e296518fef8d1acf3b1f4ec8babe8540e Mon Sep 17 00:00:00 2001 From: nocci Date: Fri, 2 May 2025 11:15:31 +0200 Subject: [PATCH 1/2] update translate.sh --- setup.sh | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/setup.sh b/setup.sh index a8585b2..095acc3 100644 --- a/setup.sh +++ b/setup.sh @@ -883,26 +883,31 @@ cat <<'SCRIPT_END' > ../translate.sh #!/bin/bash set -e -# 0.1 Change to the project directory (where docker-compose.yml is located) cd "$(dirname "$0")/steam-gift-manager" -declare -a locales=("de" "en") +declare -A locales=( + ["de"]="de" + ["en"]="en" +) -# 1. POT-Datei aktualisieren -docker-compose run --rm steam-manager pybabel extract -F babel.cfg -o translations/messages.pot . +# create POT-file +docker-compose exec steam-manager pybabel extract -F babel.cfg -o translations/messages.pot . -# 2. PO files for each language -for lang in "${locales[@]}"; do - docker-compose run --rm steam-manager pybabel update \ - -i translations/messages.pot \ - -d translations \ - -l $lang --previous +# 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]}" + fi done -# 3. Compile MO files (without fuzzy entries) -docker-compose run --rm steam-manager pybabel compile -d translations +# 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 -echo "✅ Translations successfully updated!" +echo "✅ Translations updated!" SCRIPT_END chmod +x ../translate.sh From f260da35944c45a6033b319c814f6ded38cb170b Mon Sep 17 00:00:00 2001 From: nocci Date: Fri, 2 May 2025 12:07:27 +0200 Subject: [PATCH 2/2] 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