Add Impressum and QR code management templates
- Created a new Impressum page with legal information and contact details. - Developed admin link page for linking QR codes to events with form functionality. - Implemented QR code dashboard for managing QR code sets, including creation and quick actions. - Added detailed view for QR code sets, allowing addition of QR codes and management actions. - Introduced static file serving for favicon and related images. - Established views for static content pages (about, contact, privacy, terms). - Implemented translation management scripts for compiling and updating translations.
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import gettext
|
||||
import os
|
||||
from typing import Dict, List, Callable, Any
|
||||
from fastapi import Request, Depends
|
||||
from babel.support import Translations
|
||||
from functools import lru_cache
|
||||
from gettext import gettext as _ # Ensure `_` is imported for translations
|
||||
|
||||
# Define supported languages
|
||||
SUPPORTED_LANGUAGES = {
|
||||
'en': 'English',
|
||||
'de': 'Deutsch',
|
||||
}
|
||||
|
||||
DEFAULT_LANGUAGE = 'de' # Default is German
|
||||
|
||||
# Path to translations
|
||||
LOCALE_DIR = os.path.join(os.path.dirname(__file__), 'locales')
|
||||
|
||||
@lru_cache(maxsize=None)
|
||||
def get_translation(lang_code: str) -> gettext.NullTranslations:
|
||||
"""
|
||||
Load and cache translations for the given language
|
||||
"""
|
||||
translations = gettext.translation(
|
||||
'messages',
|
||||
localedir=LOCALE_DIR,
|
||||
languages=[lang_code],
|
||||
fallback=True
|
||||
)
|
||||
return translations
|
||||
|
||||
def get_locale_from_request(request: Request) -> str:
|
||||
"""
|
||||
Determine the best language based on:
|
||||
1. URL parameter (e.g., '?lang=de')
|
||||
2. User session
|
||||
3. Accept-Language header
|
||||
4. Default language
|
||||
"""
|
||||
# Check URL parameter
|
||||
lang_param = request.query_params.get('lang')
|
||||
if lang_param in SUPPORTED_LANGUAGES:
|
||||
return lang_param
|
||||
|
||||
# Check session
|
||||
session = request.session.get('language')
|
||||
if session in SUPPORTED_LANGUAGES:
|
||||
return session
|
||||
|
||||
# Check Accept-Language header
|
||||
accept_language = request.headers.get('accept-language', '')
|
||||
if accept_language:
|
||||
for lang in accept_language.split(','):
|
||||
lang_code = lang.split(';')[0].strip().lower()
|
||||
lang_code = lang_code.split('-')[0] # Convert 'en-US' to 'en'
|
||||
if lang_code in SUPPORTED_LANGUAGES:
|
||||
return lang_code
|
||||
|
||||
return DEFAULT_LANGUAGE
|
||||
|
||||
def get_translator(locale: str = Depends(get_locale_from_request)):
|
||||
"""
|
||||
Return a FastAPI dependency that provides the translation function
|
||||
"""
|
||||
translations = get_translation(locale)
|
||||
gettext_func = translations.gettext
|
||||
|
||||
# Make the gettext function available with both _ and gettext names
|
||||
return {
|
||||
"_": gettext_func,
|
||||
"gettext": gettext_func,
|
||||
"locale": locale
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
# German translations for LeagueLedger.
|
||||
# Copyright (C) 2025 Christian Krakau-Louis
|
||||
# This file is distributed under the same license as the LeagueLedger project.
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: LeagueLedger 1.0\n"
|
||||
"Report-Msgid-Bugs-To: leagueledger@kaufdeinquiz.com\n"
|
||||
"POT-Creation-Date: 2025-04-15 12:00+0200\n"
|
||||
"PO-Revision-Date: 2025-04-15 12:00+0200\n"
|
||||
"Last-Translator: Christian Krakau-Louis <leagueledger@kaufdeinquiz.com>\n"
|
||||
"Language-Team: German\n"
|
||||
"Language: de\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
|
||||
#: app/templates/base.html:43
|
||||
msgid "Home"
|
||||
msgstr "Startseite"
|
||||
|
||||
#: app/templates/base.html:44
|
||||
msgid "Teams"
|
||||
msgstr "Teams"
|
||||
|
||||
#: app/templates/base.html:45
|
||||
msgid "Leaderboard"
|
||||
msgstr "Bestenliste"
|
||||
|
||||
#: app/templates/base.html:46
|
||||
msgid "Scan QR Code"
|
||||
msgstr "QR-Code scannen"
|
||||
|
||||
#: app/templates/base.html:55
|
||||
msgid "Profile"
|
||||
msgstr "Profil"
|
||||
|
||||
#: app/templates/base.html:58
|
||||
msgid "Dashboard"
|
||||
msgstr "Dashboard"
|
||||
|
||||
#: app/templates/base.html:61
|
||||
msgid "Admin"
|
||||
msgstr "Admin"
|
||||
|
||||
#: app/templates/base.html:66
|
||||
msgid "Logout"
|
||||
msgstr "Abmelden"
|
||||
|
||||
#: app/templates/base.html:71
|
||||
msgid "Sign In"
|
||||
msgstr "Anmelden"
|
||||
|
||||
#: app/templates/base.html:149
|
||||
msgid "Track your pub quiz team's progress."
|
||||
msgstr "Verfolgen Sie den Fortschritt Ihres Quiz-Teams."
|
||||
|
||||
#: app/templates/base.html:149
|
||||
msgid "Scan QR codes to earn points."
|
||||
msgstr "Scannen Sie QR-Codes, um Punkte zu sammeln."
|
||||
|
||||
#: app/templates/base.html:155
|
||||
msgid "Navigation"
|
||||
msgstr "Navigation"
|
||||
|
||||
#: app/templates/base.html:167
|
||||
msgid "Account"
|
||||
msgstr "Konto"
|
||||
|
||||
#: app/templates/base.html:169
|
||||
msgid "Register"
|
||||
msgstr "Registrieren"
|
||||
|
||||
#: app/templates/base.html:179
|
||||
msgid "Legal"
|
||||
msgstr "Rechtliches"
|
||||
|
||||
#: app/templates/base.html:181
|
||||
msgid "About"
|
||||
msgstr "Über uns"
|
||||
|
||||
#: app/templates/base.html:182
|
||||
msgid "Contact"
|
||||
msgstr "Kontakt"
|
||||
|
||||
#: app/templates/base.html:183
|
||||
msgid "Terms of Service"
|
||||
msgstr "Nutzungsbedingungen"
|
||||
|
||||
#: app/templates/base.html:184
|
||||
msgid "Privacy Policy"
|
||||
msgstr "Datenschutz"
|
||||
|
||||
#: app/templates/base.html:185
|
||||
msgid "Cookie Policy"
|
||||
msgstr "Cookie-Richtlinie"
|
||||
|
||||
#: app/templates/base.html:186
|
||||
msgid "Imprint"
|
||||
msgstr "Impressum"
|
||||
|
||||
#: app/templates/base.html:196
|
||||
msgid "Licensed under Apache License 2.0"
|
||||
msgstr "Lizenziert unter der Apache License 2.0"
|
||||
|
||||
#: app/templates/about.html:4
|
||||
msgid "About LeagueLedger"
|
||||
msgstr "Über LeagueLedger"
|
||||
@@ -0,0 +1,108 @@
|
||||
# English translations for LeagueLedger.
|
||||
# Copyright (C) 2025 Christian Krakau-Louis
|
||||
# This file is distributed under the same license as the LeagueLedger project.
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: LeagueLedger 1.0\n"
|
||||
"Report-Msgid-Bugs-To: leagueledger@kaufdeinquiz.com\n"
|
||||
"POT-Creation-Date: 2025-04-15 12:00+0200\n"
|
||||
"PO-Revision-Date: 2025-04-15 12:00+0200\n"
|
||||
"Last-Translator: Christian Krakau-Louis <leagueledger@kaufdeinquiz.com>\n"
|
||||
"Language-Team: English\n"
|
||||
"Language: en\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
|
||||
#: app/templates/base.html:43
|
||||
msgid "Home"
|
||||
msgstr "Home"
|
||||
|
||||
#: app/templates/base.html:44
|
||||
msgid "Teams"
|
||||
msgstr "Teams"
|
||||
|
||||
#: app/templates/base.html:45
|
||||
msgid "Leaderboard"
|
||||
msgstr "Leaderboard"
|
||||
|
||||
#: app/templates/base.html:46
|
||||
msgid "Scan QR Code"
|
||||
msgstr "Scan QR Code"
|
||||
|
||||
#: app/templates/base.html:55
|
||||
msgid "Profile"
|
||||
msgstr "Profile"
|
||||
|
||||
#: app/templates/base.html:58
|
||||
msgid "Dashboard"
|
||||
msgstr "Dashboard"
|
||||
|
||||
#: app/templates/base.html:61
|
||||
msgid "Admin"
|
||||
msgstr "Admin"
|
||||
|
||||
#: app/templates/base.html:66
|
||||
msgid "Logout"
|
||||
msgstr "Logout"
|
||||
|
||||
#: app/templates/base.html:71
|
||||
msgid "Sign In"
|
||||
msgstr "Sign In"
|
||||
|
||||
#: app/templates/base.html:149
|
||||
msgid "Track your pub quiz team's progress."
|
||||
msgstr "Track your pub quiz team's progress."
|
||||
|
||||
#: app/templates/base.html:149
|
||||
msgid "Scan QR codes to earn points."
|
||||
msgstr "Scan QR codes to earn points."
|
||||
|
||||
#: app/templates/base.html:155
|
||||
msgid "Navigation"
|
||||
msgstr "Navigation"
|
||||
|
||||
#: app/templates/base.html:167
|
||||
msgid "Account"
|
||||
msgstr "Account"
|
||||
|
||||
#: app/templates/base.html:169
|
||||
msgid "Register"
|
||||
msgstr "Register"
|
||||
|
||||
#: app/templates/base.html:179
|
||||
msgid "Legal"
|
||||
msgstr "Legal"
|
||||
|
||||
#: app/templates/base.html:181
|
||||
msgid "About"
|
||||
msgstr "About"
|
||||
|
||||
#: app/templates/base.html:182
|
||||
msgid "Contact"
|
||||
msgstr "Contact"
|
||||
|
||||
#: app/templates/base.html:183
|
||||
msgid "Terms of Service"
|
||||
msgstr "Terms of Service"
|
||||
|
||||
#: app/templates/base.html:184
|
||||
msgid "Privacy Policy"
|
||||
msgstr "Privacy Policy"
|
||||
|
||||
#: app/templates/base.html:185
|
||||
msgid "Cookie Policy"
|
||||
msgstr "Cookie Policy"
|
||||
|
||||
#: app/templates/base.html:186
|
||||
msgid "Imprint"
|
||||
msgstr "Imprint"
|
||||
|
||||
#: app/templates/base.html:196
|
||||
msgid "Licensed under Apache License 2.0"
|
||||
msgstr "Licensed under Apache License 2.0"
|
||||
|
||||
#: app/templates/about.html:4
|
||||
msgid "About LeagueLedger"
|
||||
msgstr "About LeagueLedger"
|
||||
Reference in New Issue
Block a user