feat(i18n): translate upload, import and download 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:21:50 +01:00
1 parent c65d981ae0
commit c3c698aa93
4 files changed
+20 -15

No files matched your search

@@ -1,11 +1,12 @@
using Radiosender.Models;
using Radiosender.Services.Library;
using Radiosender.Services.Localization;
namespace Radiosender.Controllers;
public class UploadController(SongImportService importService)
{
public static string FileDialogFilter { get; } = "Audiodateien (*.mp3;*.wav)|*.mp3;*.wav";
public static string FileDialogFilter => Loc.T("Import_FileFilter");
// Never throws: batch continues with next file.
public UploadResult Upload(string filePath)
@@ -13,7 +14,7 @@ public class UploadController(SongImportService importService)
try
{
var song = importService.Import(filePath);
return new UploadResult(true, $"\"{song.Title}\" ({(int)song.Duration.TotalMinutes}:{song.Duration.Seconds:00}) wurde zur Bibliothek hinzugefügt.", song);
return new UploadResult(true, Loc.F("Import_FileAdded", song.Title, $"{(int)song.Duration.TotalMinutes}:{song.Duration.Seconds:00}"), song);
}
catch (SongImportException e)
{
@@ -21,7 +22,7 @@ public class UploadController(SongImportService importService)
}
catch (Exception e)
{
return new UploadResult(false, $"Der Song konnte nicht gespeichert werden: {e.Message}");
return new UploadResult(false, Loc.F("Import_SaveFailed", e.Message));
}
}
}
+3 -1
View File
@@ -1,3 +1,5 @@
using Radiosender.Services.Localization;
namespace Radiosender.Models;
public record MusicTrack
@@ -21,5 +23,5 @@ public record MusicTrack
public bool CanImport => Duration is not null;
public string DurationText => Duration?.ToString(@"m\:ss") ?? "unbekannt";
public string DurationText => Duration?.ToString(@"m\:ss") ?? Loc.T("Song_DurationUnknown");
}
@@ -1,6 +1,7 @@
using System.IO;
using NAudio.Wave;
using Radiosender.Models;
using Radiosender.Services.Localization;
namespace Radiosender.Services.Library;
@@ -15,7 +16,7 @@ public class SongImportService(SongRepository songs, string musicDirectory)
public Song Import(string sourcePath)
{
if (!SupportedExtensions.Contains(Path.GetExtension(sourcePath).ToLowerInvariant()))
throw new SongImportException("Nur MP3- und WAV-Dateien werden unterstützt.");
throw new SongImportException(Loc.T("Song_OnlyMp3Wav"));
Directory.CreateDirectory(musicDirectory);
var targetPath = GetUniqueTargetPath(Path.GetFileName(sourcePath));
@@ -25,7 +26,7 @@ public class SongImportService(SongRepository songs, string musicDirectory)
}
catch (Exception e) when (e is IOException or UnauthorizedAccessException)
{
throw new SongImportException($"Die Datei konnte nicht gelesen werden: {e.Message}", e);
throw new SongImportException(Loc.F("Song_ReadFailed", e.Message), e);
}
try
@@ -71,11 +72,11 @@ public class SongImportService(SongRepository songs, string musicDirectory)
catch (Exception e)
{
// NAudio/Media Foundation throw many unrelated types on corrupt files.
throw new SongImportException("Die Datei ist keine lesbare MP3- oder WAV-Datei.", e);
throw new SongImportException(Loc.T("Song_NotReadable"), e);
}
if (duration <= TimeSpan.Zero)
throw new SongImportException("Die Datei enthält kein Audio.");
throw new SongImportException(Loc.T("Song_NoAudio"));
return duration;
}
@@ -1,6 +1,7 @@
using System.IO;
using System.Net.Http;
using Radiosender.Models;
using Radiosender.Services.Localization;
namespace Radiosender.Services.Providers;
@@ -20,7 +21,7 @@ public class TrackDownloader(HttpClient http, string musicFolder)
public async Task<string> DownloadAsync(MusicTrack track, CancellationToken cancellationToken = default)
{
if (!Uri.TryCreate(track.Url, UriKind.Absolute, out var uri) || uri.Scheme != Uri.UriSchemeHttps)
throw new MusicProviderException("Nur https-Downloads sind erlaubt.");
throw new MusicProviderException(Loc.T("Provider_HttpsOnly"));
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
timeout.CancelAfter(DownloadTimeout);
@@ -29,9 +30,9 @@ public class TrackDownloader(HttpClient http, string musicFolder)
{
using var response = await http.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead, timeout.Token);
if (!response.IsSuccessStatusCode)
throw new MusicProviderException($"Der Server hat HTTP {(int)response.StatusCode} geliefert.");
throw new MusicProviderException(Loc.F("Provider_ServerHttp", (int)response.StatusCode));
if (response.Content.Headers.ContentLength > MaxDownloadBytes)
throw new MusicProviderException("Die Datei ist größer als 50 MB.");
throw new MusicProviderException(Loc.T("Provider_TooLarge"));
Directory.CreateDirectory(musicFolder);
await using var file = CreateUniqueFile(track, out path);
@@ -43,11 +44,11 @@ public class TrackDownloader(HttpClient http, string musicFolder)
{
total += read;
if (total > MaxDownloadBytes)
throw new MusicProviderException("Die Datei ist größer als 50 MB.");
throw new MusicProviderException(Loc.T("Provider_TooLarge"));
await file.WriteAsync(buffer.AsMemory(0, read), timeout.Token);
}
if (total == 0)
throw new MusicProviderException("Der Download war leer.");
throw new MusicProviderException(Loc.T("Provider_EmptyDownload"));
return path;
}
catch (Exception e)
@@ -58,8 +59,8 @@ public class TrackDownloader(HttpClient http, string musicFolder)
if (e is MusicProviderException || cancellationToken.IsCancellationRequested)
throw;
throw new MusicProviderException(e is OperationCanceledException
? "Download fehlgeschlagen: Zeitüberschreitung der Anfrage."
: $"Download fehlgeschlagen: {e.Message}", e);
? Loc.T("Provider_DownloadTimeout")
: Loc.F("Provider_DownloadFailed", e.Message), e);
}
}