From 4c8740774dc7f68c20e96a6011eda939bd560481 Mon Sep 17 00:00:00 2001 From: Julian Lechner Date: Thu, 26 Nov 2026 09:22:52 +0100 Subject: [PATCH] feat(settings): choose German or English for the interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A language card on the settings page switches all texts right after saving, without a restart; German is the default and the choice is kept in settings.json. The laut.fm station ID and token fields are gone with the library provider, and the device labels now read Für die Hörer and Für dich. Co-Authored-By: Claude Opus 5.5 --- src/Radiosender/App.xaml.cs | 5 +- .../Services/Settings/AppSettings.cs | 33 +++--- src/Radiosender/Views/Pages/SettingsPage.xaml | 109 +++++++++--------- .../Views/Pages/SettingsPage.xaml.cs | 51 +++++--- 4 files changed, 110 insertions(+), 88 deletions(-) diff --git a/src/Radiosender/App.xaml.cs b/src/Radiosender/App.xaml.cs index c534879..11a47cb 100644 --- a/src/Radiosender/App.xaml.cs +++ b/src/Radiosender/App.xaml.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection; using Radiosender.Controllers; using Radiosender.Services.Audio; using Radiosender.Services.Library; +using Radiosender.Services.Localization; using Radiosender.Services.Providers; using Radiosender.Services.Scheduling; using Radiosender.Services.Settings; @@ -67,8 +68,8 @@ public partial class App : Application { base.OnStartup(e); _services = BuildServices(); - // Eager: applies settings to generator and audio output before first plan. - _services.GetRequiredService(); + // Eager: applies settings to generator and audio output before first plan, language before first window. + Loc.SetLanguage(_services.GetRequiredService().Current.Language); Wpf.Ui.Appearance.ApplicationThemeManager.ApplySystemTheme(); _services.GetRequiredService().Show(); } diff --git a/src/Radiosender/Services/Settings/AppSettings.cs b/src/Radiosender/Services/Settings/AppSettings.cs index 9548f7d..850dcf0 100644 --- a/src/Radiosender/Services/Settings/AppSettings.cs +++ b/src/Radiosender/Services/Settings/AppSettings.cs @@ -3,6 +3,7 @@ using System.Security.Cryptography; using System.Text; using System.Text.Json; using System.Text.Json.Serialization; +using Radiosender.Services.Localization; using Radiosender.Services.Scheduling; namespace Radiosender.Services.Settings; @@ -14,6 +15,8 @@ public record AppSettings private static readonly JsonSerializerOptions WriteOptions = new() { WriteIndented = true }; + public string Language { get; init; } = Loc.German; + public bool NewsAlert { get; init; } = true; public int NewsAlertSeconds { get; init; } = 30; @@ -37,8 +40,6 @@ public record AppSettings public bool LautFmEnabled { get; init; } - public string LautFmStationId { get; init; } = ""; - public string LautFmHost { get; init; } = ""; public int LautFmPort { get; init; } = 8080; @@ -47,20 +48,14 @@ public record AppSettings public string LautFmUser { get; init; } = "source"; - // Secrets: plain in memory, DPAPI-encrypted in the file via the Protected* properties. + // Secret: plain in memory, DPAPI-encrypted in the file via ProtectedLautFmPassword. [JsonIgnore] public string LautFmPassword { get; init; } = ""; - [JsonIgnore] - public string LautFmToken { get; init; } = ""; - [JsonInclude, JsonPropertyName("LautFmPassword")] private string? ProtectedLautFmPassword { get => Protect(LautFmPassword); init => LautFmPassword = Unprotect(value); } - [JsonInclude, JsonPropertyName("LautFmToken")] - private string? ProtectedLautFmToken { get => Protect(LautFmToken); init => LautFmToken = Unprotect(value); } - - // Record ToString would leak secrets into logs/debugger. + // Record ToString would leak the password into logs/debugger. public override string ToString() => nameof(AppSettings); public static string DefaultPath { get; } = Path.Combine( @@ -68,24 +63,24 @@ public record AppSettings public string? Validate() { + if (!Loc.IsSupported(Language)) + return Loc.T("Settings_LanguageUnsupported"); if (NewsAlertSeconds is < MinAlertSeconds or > MaxAlertSeconds || ModeratorAlertSeconds is < MinAlertSeconds or > MaxAlertSeconds) - return $"Die Hinweiszeit muss zwischen {MinAlertSeconds} und {MaxAlertSeconds} Sekunden liegen."; + return Loc.F("Settings_AlertSecondsRange", MinAlertSeconds, MaxAlertSeconds); if (NewsMinutesPerHour < 2) - return "Nachrichten brauchen mindestens 2 Minuten pro Stunde."; + return Loc.T("Settings_NewsMinMinutes"); if (ModeratorMinutesPerHour < 0 || AdMinutesPerHour < 0) - return "Minuten pro Stunde dürfen nicht negativ sein."; + return Loc.T("Settings_MinutesNegative"); if (NewsMinutesPerHour + ModeratorMinutesPerHour + AdMinutesPerHour > 60) - return "Nachrichten, Moderation und Werbung dürfen zusammen höchstens 60 Minuten pro Stunde dauern."; + return Loc.T("Settings_MinutesTotal"); if (LautFmEnabled) { if (string.IsNullOrWhiteSpace(LautFmHost) || Uri.CheckHostName(LautFmHost.Trim()) == UriHostNameType.Unknown) - return "Für laut.fm fehlt ein gültiger Server."; + return Loc.T("Settings_LautFmHostMissing"); if (LautFmPort is < 1 or > 65535) - return "Der laut.fm-Port muss zwischen 1 und 65535 liegen."; + return Loc.T("Settings_LautFmPortRange"); if (string.IsNullOrWhiteSpace(LautFmMount)) - return "Für laut.fm fehlt der Mountpoint."; - if (LautFmToken.Length > 0 && string.IsNullOrWhiteSpace(LautFmStationId)) - return "Für die laut.fm-Bibliothek fehlt die Stations-ID."; + return Loc.T("Settings_LautFmMountMissing"); } return null; } diff --git a/src/Radiosender/Views/Pages/SettingsPage.xaml b/src/Radiosender/Views/Pages/SettingsPage.xaml index e438980..6f1a4fa 100644 --- a/src/Radiosender/Views/Pages/SettingsPage.xaml +++ b/src/Radiosender/Views/Pages/SettingsPage.xaml @@ -2,9 +2,11 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" - Title="Einstellungen" + xmlns:l="clr-namespace:Radiosender.Views" + Title="{l:Tr Settings_Title}" Foreground="{DynamicResource TextFillColorPrimaryBrush}" - Loaded="OnLoaded"> + Loaded="OnLoaded" + Unloaded="OnUnloaded">