feat(i18n): translate live streaming and microphone messages

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
fraujulianandClaude Opus 5.5 committed 2026-11-26 09:22:25 +01:00
1 parent 8f483640cd
commit 526294ddeb
3 files changed
+20 -17

No files matched your search

@@ -1,6 +1,7 @@
using System.Net.Http; using System.Net.Http;
using NAudio.Wave; using NAudio.Wave;
using Radiosender.Services.Audio; using Radiosender.Services.Audio;
using Radiosender.Services.Localization;
using Radiosender.Services.Settings; using Radiosender.Services.Settings;
using Radiosender.Services.Streaming; using Radiosender.Services.Streaming;
@@ -43,7 +44,7 @@ public class LiveController
return; return;
var settings = _settings.Current; var settings = _settings.Current;
if (!settings.LautFmEnabled) if (!settings.LautFmEnabled)
throw new LiveStreamException("laut.fm ist in den Einstellungen ausgeschaltet."); throw new LiveStreamException(Loc.T("Live_Disabled"));
var target = IcecastTarget.From(settings); var target = IcecastTarget.From(settings);
var feed = _output.OpenLiveFeed(); var feed = _output.OpenLiveFeed();
IcecastStream stream; IcecastStream stream;
+3 -2
View File
@@ -1,4 +1,5 @@
using NAudio.Wave; using NAudio.Wave;
using Radiosender.Services.Localization;
namespace Radiosender.Services.Audio; namespace Radiosender.Services.Audio;
@@ -21,7 +22,7 @@ public sealed class Microphone(ProgramOutput output) : IDisposable
if (_capture is not null) if (_capture is not null)
return; return;
if (WaveIn.DeviceCount == 0) if (WaveIn.DeviceCount == 0)
throw new InvalidOperationException("Es wurde kein Mikrofon gefunden."); throw new InvalidOperationException(Loc.T("Audio_NoMicrophone"));
var capture = new WaveIn { WaveFormat = new WaveFormat(44100, 16, 1), BufferMilliseconds = 30 }; var capture = new WaveIn { WaveFormat = new WaveFormat(44100, 16, 1), BufferMilliseconds = 30 };
// Short dropping buffer: speech must not drift further behind. // Short dropping buffer: speech must not drift further behind.
@@ -35,7 +36,7 @@ public sealed class Microphone(ProgramOutput output) : IDisposable
catch (Exception e) when (e is NAudio.MmException or NotSupportedException) catch (Exception e) when (e is NAudio.MmException or NotSupportedException)
{ {
capture.Dispose(); capture.Dispose();
throw new InvalidOperationException($"Das Mikrofon konnte nicht eingeschaltet werden: {e.Message}", e); throw new InvalidOperationException(Loc.F("Audio_MicrophoneFailed", e.Message), e);
} }
_capture = capture; _capture = capture;
} }
@@ -4,6 +4,7 @@ using System.Net.Sockets;
using System.Text; using System.Text;
using NAudio.MediaFoundation; using NAudio.MediaFoundation;
using NAudio.Wave; using NAudio.Wave;
using Radiosender.Services.Localization;
namespace Radiosender.Services.Streaming; namespace Radiosender.Services.Streaming;
@@ -33,7 +34,7 @@ public sealed class IcecastStream : IDisposable
// Security: values go into request line/headers; a line break would inject headers. // Security: values go into request line/headers; a line break would inject headers.
if (new[] { target.Host, target.Path, target.User }.Any(value => value.Any(c => char.IsWhiteSpace(c) || char.IsControl(c))) if (new[] { target.Host, target.Path, target.User }.Any(value => value.Any(c => char.IsWhiteSpace(c) || char.IsControl(c)))
|| target.User.Contains(':')) || target.User.Contains(':'))
throw new LiveStreamException("Server, Mountpoint oder Benutzer enthalten ungültige Zeichen."); throw new LiveStreamException(Loc.T("Stream_InvalidChars"));
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); using var timeout = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
timeout.CancelAfter(ConnectTimeout); timeout.CancelAfter(ConnectTimeout);
@@ -58,10 +59,10 @@ public sealed class IcecastStream : IDisposable
{ {
throw new LiveStreamException(status switch throw new LiveStreamException(status switch
{ {
401 => "laut.fm hat die Anmeldung abgelehnt: Benutzer oder Passwort stimmen nicht.", 401 => Loc.T("Stream_LoginRefused"),
403 => "laut.fm nimmt gerade keinen Livestream an: Der Mountpoint ist belegt oder nicht freigeschaltet.", 403 => Loc.T("Stream_MountBusy"),
404 => "Diesen Mountpoint gibt es auf dem Server nicht.", 404 => Loc.T("Stream_MountMissing"),
_ => $"Der Server hat den Livestream abgelehnt (HTTP {status}).", _ => Loc.F("Stream_Rejected", status),
}); });
} }
@@ -76,8 +77,8 @@ public sealed class IcecastStream : IDisposable
throw; throw;
throw ex switch throw ex switch
{ {
OperationCanceledException => new LiveStreamException("Der laut.fm-Server antwortet nicht.", ex), OperationCanceledException => new LiveStreamException(Loc.T("Stream_NoResponse"), ex),
SocketException or IOException => new LiveStreamException($"Keine Verbindung zum laut.fm-Server: {ex.Message}", ex), SocketException or IOException => new LiveStreamException(Loc.F("Stream_NoConnection", ex.Message), ex),
_ => ex, _ => ex,
}; };
} }
@@ -97,11 +98,11 @@ public sealed class IcecastStream : IDisposable
{ {
using var response = await http.SendAsync(request, cancellationToken); using var response = await http.SendAsync(request, cancellationToken);
if (!response.IsSuccessStatusCode) if (!response.IsSuccessStatusCode)
throw new LiveStreamException($"laut.fm hat den Titel nicht angenommen (HTTP {(int)response.StatusCode})."); throw new LiveStreamException(Loc.F("Stream_TitleRejected", (int)response.StatusCode));
} }
catch (Exception ex) when (ex is HttpRequestException or TaskCanceledException && !cancellationToken.IsCancellationRequested) catch (Exception ex) when (ex is HttpRequestException or TaskCanceledException && !cancellationToken.IsCancellationRequested)
{ {
throw new LiveStreamException($"Der Titel konnte nicht an laut.fm gesendet werden: {ex.Message}", ex); throw new LiveStreamException(Loc.F("Stream_TitleFailed", ex.Message), ex);
} }
} }
@@ -122,17 +123,17 @@ public sealed class IcecastStream : IDisposable
MediaFoundationApi.Startup(); MediaFoundationApi.Startup();
var pcm = _reader.ToSampleProvider().ToWaveProvider16(); var pcm = _reader.ToSampleProvider().ToWaveProvider16();
var mediaType = MediaFoundationEncoder.SelectMediaType(AudioSubtypes.MFAudioFormat_MP3, pcm.WaveFormat, Bitrate) var mediaType = MediaFoundationEncoder.SelectMediaType(AudioSubtypes.MFAudioFormat_MP3, pcm.WaveFormat, Bitrate)
?? throw new LiveStreamException("Windows hat keinen MP3-Encoder."); ?? throw new LiveStreamException(Loc.T("Stream_NoEncoder"));
using var encoder = new MediaFoundationEncoder(mediaType); using var encoder = new MediaFoundationEncoder(mediaType);
encoder.Encode(_client.GetStream(), pcm, TranscodeContainerTypes.MFTranscodeContainerType_MP3); encoder.Encode(_client.GetStream(), pcm, TranscodeContainerTypes.MFTranscodeContainerType_MP3);
if (!_stopping) if (!_stopping)
Failed?.Invoke(this, "Der Livestream wurde unerwartet beendet."); Failed?.Invoke(this, Loc.T("Stream_EndedUnexpectedly"));
} }
catch (Exception ex) catch (Exception ex)
{ {
// Stopping: socket closed under the encoder is expected. // Stopping: socket closed under the encoder is expected.
if (!_stopping) if (!_stopping)
Failed?.Invoke(this, ex is LiveStreamException ? ex.Message : $"Verbindung zu laut.fm verloren: {ex.Message}"); Failed?.Invoke(this, ex is LiveStreamException ? ex.Message : Loc.F("Stream_ConnectionLost", ex.Message));
} }
} }
@@ -144,13 +145,13 @@ public sealed class IcecastStream : IDisposable
{ {
var read = await network.ReadAsync(buffer, cancellationToken); var read = await network.ReadAsync(buffer, cancellationToken);
if (read == 0 || header.Length > 8192) if (read == 0 || header.Length > 8192)
throw new LiveStreamException("Der Server hat die Verbindung ohne gültige Antwort beendet."); throw new LiveStreamException(Loc.T("Stream_NoValidReply"));
header.Append(Encoding.ASCII.GetString(buffer, 0, read)); header.Append(Encoding.ASCII.GetString(buffer, 0, read));
} }
var parts = header.ToString().Split(' ', 3); var parts = header.ToString().Split(' ', 3);
return parts.Length >= 2 && int.TryParse(parts[1], out var status) return parts.Length >= 2 && int.TryParse(parts[1], out var status)
? status ? status
: throw new LiveStreamException("Der Server hat ungültig geantwortet."); : throw new LiveStreamException(Loc.T("Stream_InvalidReply"));
} }
// Empty feed: wait instead of ending, so the encoder runs in real time. // Empty feed: wait instead of ending, so the encoder runs in real time.