diff --git a/.env.example b/.env.example index d9c5d79..6f20ef2 100644 --- a/.env.example +++ b/.env.example @@ -7,4 +7,6 @@ SPOTIPY_REDIRECT_URI=http://localhost:5000/callback SECRET_KEY=dein_geheimer_flask_key # Flask Umgebung (optional) -FLASK_ENV=development \ No newline at end of file +FLASK_ENV=development + +LANG=de-DE \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b7503ef..422c736 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,7 @@ ENV SPOTIPY_CLIENT_ID=$SPOTIPY_CLIENT_ID ENV SPOTIPY_CLIENT_SECRET=$SPOTIPY_CLIENT_SECRET ENV SPOTIPY_REDIRECT_URI=$SPOTIPY_REDIRECT_URI ENV FLASK_ENV=development +ENV LANG=$LANG # Starten mit Gunicorn für Production CMD ["python", "app.py"] diff --git a/app.py b/app.py index 987a584..c7f2b91 100644 --- a/app.py +++ b/app.py @@ -9,6 +9,7 @@ from spotipy.oauth2 import SpotifyOAuth import random from difflib import SequenceMatcher import re +import json app = Flask(__name__) app.secret_key = os.getenv("SECRET_KEY") @@ -16,6 +17,20 @@ app.secret_key = os.getenv("SECRET_KEY") # Erweiterte Berechtigungen für Web Playback SDK SCOPE = "user-library-read playlist-read-private streaming user-read-email user-read-private" +def get_locale(): + return os.getenv("LANG", "de-DE") + +def get_translations(): + lang = get_locale() + path = os.path.join(os.path.dirname(__file__), "locales", f"{lang}.json") + try: + with open(path, encoding="utf-8") as f: + return json.load(f) + except Exception: + # Fallback auf Deutsch + with open(os.path.join(os.path.dirname(__file__), "locales", "de-DE.json"), encoding="utf-8") as f: + return json.load(f) + def get_spotify_client(): token_info = session.get("token_info", None) if not token_info: @@ -150,7 +165,8 @@ def quiz(playlist_id): question_number=len(played_tracks), total_questions=len(tracks), score=score, - answered=answered + answered=answered, + translations=get_translations() ) @app.route("/search_track", methods=["POST"]) diff --git a/locales/de-DE.json b/locales/de-DE.json new file mode 100644 index 0000000..36a22c2 --- /dev/null +++ b/locales/de-DE.json @@ -0,0 +1,24 @@ +{ + "login_title": "Login mit Spotify", + "login_button": "Mit Spotify einloggen", + "quiz_title": "Musik Quiz", + "choose_playlist": "Wähle eine Playlist:", + "guess_artist": "Künstler erraten", + "guess_title": "Titel erraten", + "guess_year": "Jahr erraten", + "question_artist": "Wer ist der Künstler dieses Songs?", + "question_title": "Wie heißt dieser Song?", + "question_year": "In welchem Jahr wurde dieser Song veröffentlicht?", + "input_artist": "Künstlername eingeben...", + "input_title": "Songtitel eingeben...", + "input_year": "Jahr eingeben...", + "answer_button": "Antworten", + "next_question": "Nächste Frage", + "quiz_end": "Quiz beenden", + "tip_artist": "Tipp: Gib den Namen des Künstlers ein, der diesen Song performt.", + "tip_title": "Tipp: Gib den Titel des Songs ein, den du gerade hörst.", + "tip_year": "Tipp: Gib das Erscheinungsjahr des Songs ein.", + "correct": "Richtig! 🎉", + "wrong": "Falsch 😢", + "right_answer": "Die richtige Antwort ist:" +} \ No newline at end of file diff --git a/templates/login.html b/templates/login.html index e58dfdd..2db753d 100644 --- a/templates/login.html +++ b/templates/login.html @@ -1,7 +1,7 @@
-