multilang_1

This commit is contained in:
Mateusz Gruszczyński
2026-05-29 13:18:53 +02:00
parent 4c8debb103
commit 22e2983dc2
17 changed files with 4569 additions and 152 deletions

View File

@@ -28,6 +28,18 @@ FONT_FAMILIES = {
"adwaita-mono": "Adwaita Mono",
}
SUPPORTED_LANGUAGES = {
"en_US": {"label": "English", "flag": "us"},
"pl_PL": {"label": "Polski", "flag": "pl"},
"de_DE": {"label": "Deutsch", "flag": "de"},
"nb_NO": {"label": "Norsk bokmål", "flag": "no"},
"ru_RU": {"label": "Русский", "flag": "ru"},
"fr_FR": {"label": "Français", "flag": "fr"},
"cs_CZ": {"label": "Čeština", "flag": "cz"},
"es_ES": {"label": "Español", "flag": "es"},
}
# Note: Backend owns the recommended torrent table layout so frontend builds do not duplicate presets.
RECOMMENDED_TABLE_COLUMNS = {
"hidden": ["hash", "priority", "hashing", "active", "message", "complete", "state", "ratio_group"],
@@ -445,7 +457,7 @@ def get_preferences(user_id: int | None = None, profile_id: int | None = None):
pref = conn.execute("SELECT * FROM user_preferences WHERE user_id=?", (user_id,)).fetchone()
if not pref:
now = utcnow()
conn.execute("INSERT INTO user_preferences(user_id, theme, created_at, updated_at) VALUES(?, 'dark', ?, ?)", (user_id, now, now))
conn.execute("INSERT INTO user_preferences(user_id, theme, language, created_at, updated_at) VALUES(?, 'dark', 'en_US', ?, ?)", (user_id, now, now))
pref = conn.execute("SELECT * FROM user_preferences WHERE user_id=?", (user_id,)).fetchone()
merged = dict(pref or {})
if profile_id:
@@ -457,6 +469,7 @@ def save_preferences(data: dict, user_id: int | None = None):
user_id = user_id or auth.current_user_id() or default_user_id()
profile_id = _active_profile_id_for_user(user_id)
allowed_theme = data.get("theme") if data.get("theme") in {"light", "dark"} else None
language = data.get("language") if data.get("language") in SUPPORTED_LANGUAGES else None
bootstrap_theme = data.get("bootstrap_theme") if data.get("bootstrap_theme") in BOOTSTRAP_THEMES else None
font_family = data.get("font_family") if data.get("font_family") in FONT_FAMILIES else None
footer_items_json = data.get("footer_items_json")
@@ -487,6 +500,9 @@ def save_preferences(data: dict, user_id: int | None = None):
now = utcnow()
if allowed_theme:
conn.execute("UPDATE user_preferences SET theme=?, updated_at=? WHERE user_id=?", (allowed_theme, now, user_id))
if language:
# Note: Language is stored per user so every account keeps its own UI locale across profiles.
conn.execute("UPDATE user_preferences SET language=?, updated_at=? WHERE user_id=?", (language, now, user_id))
if bootstrap_theme:
conn.execute("UPDATE user_preferences SET bootstrap_theme=?, updated_at=? WHERE user_id=?", (bootstrap_theme, now, user_id))
if font_family: