Urgent Fix for Translations

This commit is contained in:
nocci 2025-04-29 18:02:22 +02:00
parent fb6a2799ce
commit b1aee9e5b8
6 changed files with 133 additions and 122 deletions

View File

@ -1,13 +1,13 @@
#!/bin/bash
set -e
# Color definitions
# Colors
RED='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
# 1. Docker check (including Arch Linux)
# 1. Docker check (incl. Arch Linux)
if ! command -v docker &>/dev/null; then
echo -e "${RED}❗ Docker is not installed.${NC}"
read -p "Would you like to install Docker automatically now? [y/N]: " install_docker
@ -23,7 +23,7 @@ if ! command -v docker &>/dev/null; then
rm get-docker.sh
fi
# Check Docker group membership
# Docker group membership prüfen
if ! groups | grep -q '\bdocker\b'; then
echo -e "${YELLOW}⚠️ Your user is not in the docker group. Adding now...${NC}"
sudo usermod -aG docker $USER
@ -37,7 +37,7 @@ if ! command -v docker &>/dev/null; then
fi
fi
# 2. Docker Compose check (V1 and V2 plugin, with Arch support)
# 2. Check Docker compose (V1 und V2 Plugin, incl. Arch Support)
DOCKER_COMPOSE_CMD=""
if command -v docker-compose &>/dev/null; then
DOCKER_COMPOSE_CMD="docker-compose"
@ -74,13 +74,12 @@ else
fi
fi
# Configuration
PROJECT_DIR="steam-gift-manager"
TRANSLATIONS_DIR="../translations"
DATA_DIR="../data"
TRANSLATIONS_DIR="$PWD/translations"
DATA_DIR="$PWD/data"
# 1. Create project folder & translations folder
# 1. Create folders
mkdir -p "$PROJECT_DIR"/{templates,static}
mkdir -p "$TRANSLATIONS_DIR"/de/LC_MESSAGES
mkdir -p "$TRANSLATIONS_DIR"/en/LC_MESSAGES
@ -111,7 +110,7 @@ pillow
gunicorn
EOL
# 3. Create .env file in parent directory
# 3. .env Datei in Parent-VFolder
cd ..
SECRET_KEY=$(python3 -c 'import secrets; print(secrets.token_hex(24))')
REDEEM_SECRET=$(python3 -c 'import secrets; print(secrets.token_hex(16))')
@ -154,13 +153,11 @@ MATRIX_ACCESS_TOKEN=""
MATRIX_ROOM_ID=""
EOL
# Back to project directory
cd $PROJECT_DIR
# 4. app.py (the main app)
cat <<'PYTHON_END' > app.py
import os
import logging
import warnings
from sqlalchemy.exc import LegacyAPIWarning
warnings.simplefilter("ignore", category=LegacyAPIWarning)
@ -202,8 +199,11 @@ from reportlab.lib.utils import ImageReader
from reportlab.lib.units import cm, inch, mm
from io import BytesIO
import reportlab.lib
import logging
logging.basicConfig()
logging.getLogger('babel').setLevel(logging.DEBUG)
app = Flask(__name__)
csrf = CSRFProtect(app)
convention = {
@ -223,14 +223,19 @@ load_dotenv(override=True)
# App-Configuration
app.config.update(
SECRET_KEY=os.getenv('SECRET_KEY'),
SQLALCHEMY_DATABASE_URI=('sqlite:////app/data/games.db'),
SQLALCHEMY_DATABASE_URI='sqlite:////app/data/games.db',
SQLALCHEMY_TRACK_MODIFICATIONS=False,
BABEL_DEFAULT_LOCALE=os.getenv('BABEL_DEFAULT_LOCALE'),
BABEL_SUPPORTED_LOCALES=os.getenv('BABEL_SUPPORTED_LOCALES').split(','),
BABEL_TRANSLATION_DIRECTORIES=os.getenv('BABEL_TRANSLATION_DIRECTORIES'),
SESSION_COOKIE_SECURE=os.getenv('SESSION_COOKIE_SECURE') == 'True',
WTF_CSRF_ENABLED=os.getenv('CSRF_ENABLED') == 'True',
REGISTRATION_ENABLED=os.getenv('REGISTRATION_ENABLED', 'True').lower() == 'true'
BABEL_DEFAULT_LOCALE=os.getenv('BABEL_DEFAULT_LOCALE', 'en'),
BABEL_SUPPORTED_LOCALES=os.getenv('BABEL_SUPPORTED_LOCALES', 'de,en').split(','),
BABEL_TRANSLATION_DIRECTORIES=os.path.join(app.root_path, 'translations'),
SESSION_COOKIE_SECURE=os.getenv('SESSION_COOKIE_SECURE', 'False') == 'True',
SESSION_COOKIE_SAMESITE='Lax',
PERMANENT_SESSION_LIFETIME=timedelta(days=30),
SESSION_REFRESH_EACH_REQUEST=False,
WTF_CSRF_ENABLED=os.getenv('CSRF_ENABLED', 'True') == 'True',
REGISTRATION_ENABLED=os.getenv('REGISTRATION_ENABLED', 'True').lower() == 'true',
SEND_FILE_MAX_AGE_DEFAULT=int(os.getenv('SEND_FILE_MAX_AGE_DEFAULT', 0)),
TEMPLATES_AUTO_RELOAD=os.getenv('TEMPLATES_AUTO_RELOAD', 'True') == 'True'
)
interval_hours = int(os.getenv('CHECK_EXPIRING_KEYS_INTERVAL_HOURS', 12))
@ -252,6 +257,11 @@ def get_locale():
return session['lang']
return request.accept_languages.best_match(app.config['BABEL_SUPPORTED_LOCALES'])
@app.before_request
def reload_translations():
if app.config['DEBUG']:
babel.reload()
@app.context_processor
def inject_template_vars():
return dict(
@ -718,6 +728,13 @@ def redeem_page(token):
redeem_token=redeem_token,
platform_link='https://store.steampowered.com/account/registerkey?key=' if game.steam_appid else 'https://www.gog.com/redeem')
@app.route('/debug-session')
def debug_session():
return jsonify({
'session_lang': session.get('lang'),
'config_locales': app.config['BABEL_SUPPORTED_LOCALES']
})
# Benachrichtigungsfunktionen
def send_pushover_notification(user, game):
"""Sendet Pushover-Benachrichtigung für ablaufenden Key"""
@ -897,46 +914,44 @@ services:
- TZ=${TZ}
volumes:
- ../data:/app/data
- ../translations:/app/translations
- ../translations:/app/translations:rw
- ../.env:/app/.env
user: "1000:1000"
user: "${UID}:${GID}"
restart: unless-stopped
COMPOSE_END
# 7. Directories and permissions
mkdir -p ../data ../translations
chmod -R a+rwX ../data ../translations
find ../data ../translations -type d -exec chmod 775 {} \;
find ../data ../translations -type f -exec chmod 664 {} \;
# 8. Translation and upgrade scripts
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"]="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 .
# 1. POT-Datei aktualisieren
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]}"
fi
# 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
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
# 3. Compile MO files (without fuzzy entries)
docker-compose run --rm steam-manager pybabel compile -d translations
echo "✅ Translations updated!"
echo "✅ Translations successfully updated!"
SCRIPT_END
chmod +x ../translate.sh
@ -1005,6 +1020,8 @@ cat <<HTML_END > templates/base.html
<label class="form-check-label" for="darkModeSwitch">{{ _('Dark Mode') }}</label>
</div>
<div class="dropdown ms-3">
<!-- DEBUG: Current locale {{ get_locale() }} -->
<div hidden id="locale-debug" data-locale="{{ get_locale() }}"></div>
<button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
{% if get_locale() == 'de' %} Deutsch {% elif get_locale() == 'en' %} English {% else %} Sprache {% endif %}
</button>

View File

@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2025-04-29 13:06+0000\n"
"PO-Revision-Date: 2025-04-29 13:06+0000\n"
"POT-Creation-Date: 2025-04-29 15:53+0000\n"
"PO-Revision-Date: 2025-04-29 15:42+0000\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: de\n"
"Language-Team: de <LL@li.org>\n"
@ -18,63 +18,63 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.17.0\n"
#: app.py:187
#: app.py:194
msgid "Invalid credentials"
msgstr "Ungültige Anmeldedaten"
#: app.py:193
#: app.py:200
msgid "No new registrations. They are deactivated!"
msgstr "Upps. Keine neuen Registrierungen, sorry!"
msgstr "Keine neuen Registrierungen. Sie sind deaktiviert!"
#: app.py:201
#: app.py:208
msgid "Username already exists"
msgstr "Benutzername existiert bereits"
#: app.py:227
#: app.py:234
msgid "Current passwort is wrong"
msgstr "Das aktuelle Passwort ist falsch"
msgstr "Aktuelles Passwort ist falsch"
#: app.py:231
#: app.py:238
msgid "New Passwords are not matching"
msgstr "Die neuen Passwörter stimmen nicht überein"
msgstr "Neue Passwörter stimmen nicht überein"
#: app.py:236
#: app.py:243
msgid "Password changed successfully"
msgstr "Passwort erfolgreich geändert"
#: app.py:266
#: app.py:273
msgid "Game added successfully!"
msgstr "Spiel erfolgreich hinzugefügt!"
#: app.py:271
#: app.py:278
msgid "Steam Key already exists!"
msgstr "Game-Key existiert bereits!"
msgstr "Steam-Key existiert bereits!"
#: app.py:274 app.py:318
#: app.py:281 app.py:325
msgid "Error: "
msgstr "Fehler: "
#: app.py:313
#: app.py:320
msgid "Changes saved!"
msgstr "Änderungen gespeichert!"
#: app.py:401
#: app.py:408
msgid "Game List (without Keys)"
msgstr "Spieleliste (ohne Keys)"
#: app.py:494
#: app.py:501
#, python-format
msgid "%(new)d new games imported, %(dup)d skipped duplicates"
msgstr "%(new)d neue Spiele importiert, %(dup)d Duplikate übersprungen"
#: app.py:498
#: app.py:505
#, python-format
msgid "Import error: %(error)s"
msgstr "Importfehler: %(error)s"
#: app.py:502
#: app.py:509
msgid "Please upload a valid CSV file."
msgstr "Bitte lade eine gültige CSV-Datei hoch."
msgstr "Bitte eine gültige CSV-Datei hochladen."
#: templates/add_game.html:4 templates/index.html:9
msgid "Add New Game"
@ -86,32 +86,27 @@ msgstr "Name"
#: templates/add_game.html:13 templates/edit_game.html:13
msgid "Game Key"
msgstr "Spiel-Key"
msgstr "Spiele-Key"
#: templates/add_game.html:17 templates/edit_game.html:21
#: templates/index.html:21
#: templates/add_game.html:17 templates/edit_game.html:21 templates/index.html:21
msgid "Status"
msgstr "Status"
#: templates/add_game.html:19 templates/edit_game.html:23
#: templates/index.html:41
#: templates/add_game.html:19 templates/edit_game.html:23 templates/index.html:41
msgid "Not redeemed"
msgstr "Nicht eingelöst"
#: templates/add_game.html:20 templates/edit_game.html:24
#: templates/index.html:43
#: templates/add_game.html:20 templates/edit_game.html:24 templates/index.html:43
msgid "Gifted"
msgstr ""
#: templates/add_game.html:21 templates/edit_game.html:25
#: templates/index.html:45
msgid "Redeemed"
msgstr "Verschenkt"
#: templates/add_game.html:25 templates/edit_game.html:29
#: templates/index.html:23
#: templates/add_game.html:21 templates/edit_game.html:25 templates/index.html:45
msgid "Redeemed"
msgstr "Eingelöst"
#: templates/add_game.html:25 templates/edit_game.html:29 templates/index.html:23
msgid "Redeem by"
msgstr "Einzulösen vor"
msgstr "Einzulösen bis"
#: templates/add_game.html:29 templates/edit_game.html:33
msgid "Recipient"
@ -129,14 +124,13 @@ msgstr "Notizen"
msgid "Save"
msgstr "Speichern"
#: templates/add_game.html:42 templates/edit_game.html:61
#: templates/import.html:12
#: templates/add_game.html:42 templates/edit_game.html:61 templates/import.html:12
msgid "Cancel"
msgstr "Abbrechen"
#: templates/base.html:7
msgid "Game Key Manager"
msgstr "Game Key Manager"
msgstr "Game-Key-Verwaltung"
#: templates/base.html:23
msgid "Search"
@ -144,13 +138,13 @@ msgstr "Suche"
#: templates/base.html:31
msgid "Dark Mode"
msgstr "Dark Mode"
msgstr "Dunkler Modus"
#: templates/base.html:44 templates/login.html:16 templates/register.html:15
#: templates/base.html:46 templates/login.html:16 templates/register.html:15
msgid "Password"
msgstr "Passwort"
#: templates/base.html:47
#: templates/base.html:49
msgid "Logout"
msgstr "Abmelden"
@ -176,7 +170,7 @@ msgstr "Spiel bearbeiten"
#: templates/edit_game.html:17
msgid "Steam AppID (optional)"
msgstr "Steam AppID (optional)"
msgstr "Steam-AppID (optional)"
#: templates/edit_game.html:47
msgid "Active Redeem Link"
@ -184,7 +178,7 @@ msgstr "Aktiver Einlöse-Link"
#: templates/edit_game.html:54
msgid "Expires at"
msgstr "Läuft ab"
msgstr "Ablaufdatum"
#: templates/import.html:4
msgid "Import Games"
@ -232,7 +226,7 @@ msgstr "Aktionen"
#: templates/index.html:63
msgid "Generate redeem link"
msgstr "Geschenk-Link generieren"
msgstr "Einlöse-Link generieren"
#: templates/index.html:70
msgid "Really delete?"
@ -240,7 +234,7 @@ msgstr "Wirklich löschen?"
#: templates/index.html:96
msgid "Redeem link copied to clipboard!"
msgstr "Geschenk-Link in die Zwischenablage kopiert!"
msgstr "Einlöse-Link in die Zwischenablage kopiert!"
#: templates/index.html:100
msgid "Error generating link"
@ -260,7 +254,7 @@ msgstr "Benutzername"
#: templates/login.html:22
msgid "No account yet? Register"
msgstr "Noch kein Konto? Registrieren"
msgstr "Noch kein Konto? Jetzt registrieren"
#: templates/redeem.html:16
msgid "Your Key:"
@ -268,7 +262,7 @@ msgstr "Dein Key:"
#: templates/redeem.html:22
msgid "Redeem now on"
msgstr "Jetzt einlösen auf"
msgstr "Jetzt einlösen bei"
#: templates/redeem.html:26
msgid "This page will expire in"

View File

@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2025-04-29 13:06+0000\n"
"PO-Revision-Date: 2025-04-29 13:06+0000\n"
"POT-Creation-Date: 2025-04-29 15:53+0000\n"
"PO-Revision-Date: 2025-04-29 15:42+0000\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en\n"
"Language-Team: en <LL@li.org>\n"
@ -18,61 +18,61 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.17.0\n"
#: app.py:187
#: app.py:194
msgid "Invalid credentials"
msgstr ""
#: app.py:193
#: app.py:200
msgid "No new registrations. They are deactivated!"
msgstr ""
#: app.py:201
#: app.py:208
msgid "Username already exists"
msgstr ""
#: app.py:227
#: app.py:234
msgid "Current passwort is wrong"
msgstr ""
#: app.py:231
#: app.py:238
msgid "New Passwords are not matching"
msgstr ""
#: app.py:236
#: app.py:243
msgid "Password changed successfully"
msgstr ""
#: app.py:266
#: app.py:273
msgid "Game added successfully!"
msgstr ""
#: app.py:271
#: app.py:278
msgid "Steam Key already exists!"
msgstr ""
#: app.py:274 app.py:318
#: app.py:281 app.py:325
msgid "Error: "
msgstr ""
#: app.py:313
#: app.py:320
msgid "Changes saved!"
msgstr ""
#: app.py:401
#: app.py:408
msgid "Game List (without Keys)"
msgstr ""
#: app.py:494
#: app.py:501
#, python-format
msgid "%(new)d new games imported, %(dup)d skipped duplicates"
msgstr ""
#: app.py:498
#: app.py:505
#, python-format
msgid "Import error: %(error)s"
msgstr ""
#: app.py:502
#: app.py:509
msgid "Please upload a valid CSV file."
msgstr ""
@ -146,11 +146,11 @@ msgstr ""
msgid "Dark Mode"
msgstr ""
#: templates/base.html:44 templates/login.html:16 templates/register.html:15
#: templates/base.html:46 templates/login.html:16 templates/register.html:15
msgid "Password"
msgstr ""
#: templates/base.html:47
#: templates/base.html:49
msgid "Logout"
msgstr ""

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2025-04-29 13:06+0000\n"
"POT-Creation-Date: 2025-04-29 15:53+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,61 +17,61 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.17.0\n"
#: app.py:187
#: app.py:194
msgid "Invalid credentials"
msgstr ""
#: app.py:193
#: app.py:200
msgid "No new registrations. They are deactivated!"
msgstr ""
#: app.py:201
#: app.py:208
msgid "Username already exists"
msgstr ""
#: app.py:227
#: app.py:234
msgid "Current passwort is wrong"
msgstr ""
#: app.py:231
#: app.py:238
msgid "New Passwords are not matching"
msgstr ""
#: app.py:236
#: app.py:243
msgid "Password changed successfully"
msgstr ""
#: app.py:266
#: app.py:273
msgid "Game added successfully!"
msgstr ""
#: app.py:271
#: app.py:278
msgid "Steam Key already exists!"
msgstr ""
#: app.py:274 app.py:318
#: app.py:281 app.py:325
msgid "Error: "
msgstr ""
#: app.py:313
#: app.py:320
msgid "Changes saved!"
msgstr ""
#: app.py:401
#: app.py:408
msgid "Game List (without Keys)"
msgstr ""
#: app.py:494
#: app.py:501
#, python-format
msgid "%(new)d new games imported, %(dup)d skipped duplicates"
msgstr ""
#: app.py:498
#: app.py:505
#, python-format
msgid "Import error: %(error)s"
msgstr ""
#: app.py:502
#: app.py:509
msgid "Please upload a valid CSV file."
msgstr ""
@ -145,11 +145,11 @@ msgstr ""
msgid "Dark Mode"
msgstr ""
#: templates/base.html:44 templates/login.html:16 templates/register.html:15
#: templates/base.html:46 templates/login.html:16 templates/register.html:15
msgid "Password"
msgstr ""
#: templates/base.html:47
#: templates/base.html:49
msgid "Logout"
msgstr ""