diff options
Diffstat (limited to 'Emby.Server.Implementations/Localization')
| -rw-r--r-- | Emby.Server.Implementations/Localization/Core/en-US.json | 4 | ||||
| -rw-r--r-- | Emby.Server.Implementations/Localization/LocalizationManager.cs | 48 |
2 files changed, 28 insertions, 24 deletions
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<CultureInfo>(); 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; } + /// <summary> + /// Resolves a Jellyfin resource culture code (which may use underscores, e.g. <c>es_419</c>) + /// to a <see cref="CultureInfo"/>. Returns <see langword="false"/> for codes .NET cannot resolve. + /// </summary> + 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; - } } /// <inheritdoc /> |
