From 7a5181c3fd3aea8a9913fe07086970c39c9bc1c4 Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Thu, 14 May 2026 07:46:43 +0200 Subject: Address review comments --- .../Localization/Core/en-US.json | 4 +- .../Localization/LocalizationManager.cs | 48 ++++++++++++---------- 2 files changed, 28 insertions(+), 24 deletions(-) (limited to 'Emby.Server.Implementations') diff --git a/Emby.Server.Implementations/Localization/Core/en-US.json b/Emby.Server.Implementations/Localization/Core/en-US.json index ff674bd0d0..856941c61a 100644 --- a/Emby.Server.Implementations/Localization/Core/en-US.json +++ b/Emby.Server.Implementations/Localization/Core/en-US.json @@ -93,8 +93,8 @@ "TaskUpdatePluginsDescription": "Downloads and installs updates for plugins that are configured to update automatically.", "TaskCleanTranscode": "Clean Transcode Directory", "TaskCleanTranscodeDescription": "Deletes transcode files more than one day old.", - "TasksRefreshChannels": "Refresh Channels", - "TasksRefreshChannelsDescription": "Refreshes internet channel information.", + "TaskRefreshChannels": "Refresh Channels", + "TaskRefreshChannelsDescription": "Refreshes internet channel information.", "TaskDownloadMissingLyrics": "Download missing lyrics", "TaskDownloadMissingLyricsDescription": "Downloads lyrics for songs", "TaskDownloadMissingSubtitles": "Download missing subtitles", diff --git a/Emby.Server.Implementations/Localization/LocalizationManager.cs b/Emby.Server.Implementations/Localization/LocalizationManager.cs index 94aa933c92..0b0b300d30 100644 --- a/Emby.Server.Implementations/Localization/LocalizationManager.cs +++ b/Emby.Server.Implementations/Localization/LocalizationManager.cs @@ -77,22 +77,36 @@ namespace Emby.Server.Implementations.Localization var cultures = new List(); foreach (var option in _localizationOptions) { - // Resource files use underscores for some variants (e.g. es_419); - // CultureInfo only accepts hyphenated BCP-47 codes. - var code = option.Value.Replace('_', '-'); - try - { - cultures.Add(CultureInfo.GetCultureInfo(code)); - } - catch (CultureNotFoundException) + // Skip novelty codes (e.g. "pr" Pirate, "jbo" Lojban) that .NET cannot resolve. + if (TryGetCultureInfo(option.Value, out var cultureInfo)) { - // Skip novelty codes (e.g. "pr" Pirate, "jbo" Lojban) that .NET cannot resolve. + cultures.Add(cultureInfo); } } return cultures; } + /// + /// Resolves a Jellyfin resource culture code (which may use underscores, e.g. es_419) + /// to a . Returns for codes .NET cannot resolve. + /// + private static bool TryGetCultureInfo(string cultureCode, [NotNullWhen(true)] out CultureInfo? cultureInfo) + { + try + { + // Resource files use underscores for some variants (e.g. es_419); + // CultureInfo only accepts hyphenated BCP-47 codes. + cultureInfo = CultureInfo.GetCultureInfo(cultureCode.Replace('_', '-')); + return true; + } + catch (CultureNotFoundException) + { + cultureInfo = null; + return false; + } + } + private static void OnConfigurationUpdated(object? sender, EventArgs e) { if (sender is IServerConfigurationManager configManager) @@ -614,20 +628,10 @@ namespace Emby.Server.Implementations.Localization private static string GetDisplayName(string cultureCode) { - // Resource files use underscores for codes that .NET's CultureInfo doesn't accept directly (e.g. es_419). - var lookup = cultureCode.Contains('_', StringComparison.Ordinal) - ? cultureCode.Replace('_', '-') + // Custom/novelty codes like "pr" (Pirate) — fall back to code itself + return TryGetCultureInfo(cultureCode, out var cultureInfo) + ? cultureInfo.NativeName : cultureCode; - - try - { - return CultureInfo.GetCultureInfo(lookup).NativeName; - } - catch (CultureNotFoundException) - { - // Custom/novelty codes like "pr" (Pirate) — fall back to code itself - return cultureCode; - } } /// -- cgit v1.2.3