From a2ca4a7b84e89957547a9fb04a190b139c86e72f Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Fri, 20 Nov 2026 07:25:01 -0500 Subject: Backport pull request #18072 from jellyfin/release-12.z Keep language variants distinguishable Original-merge: 060233101dc336560b2f97d251fe7a9f8241b763 Merged-by: crobibero Backported-by: Cody Robibero --- .../Localization/LocalizationManager.cs | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'Emby.Server.Implementations/Localization/LocalizationManager.cs') diff --git a/Emby.Server.Implementations/Localization/LocalizationManager.cs b/Emby.Server.Implementations/Localization/LocalizationManager.cs index 7af545c550..c11a0bcc63 100644 --- a/Emby.Server.Implementations/Localization/LocalizationManager.cs +++ b/Emby.Server.Implementations/Localization/LocalizationManager.cs @@ -53,6 +53,16 @@ namespace Emby.Server.Implementations.Localization private FrozenDictionary _iso6392BtoT = null!; + // Jellyfin's own pre-12.0 codes for region qualified languages and the legacy OpenSubtitles + // ones, still stored in existing configuration and common in file names (movie.pob.srt). + private static readonly FrozenDictionary _legacyLanguageAliases = new Dictionary(StringComparer.OrdinalIgnoreCase) + { + { "pob", "pt-br" }, + { "pb", "pt-br" }, + { "pop", "pt-pt" }, + { "es-mx", "es-419" }, + }.ToFrozenDictionary(StringComparer.OrdinalIgnoreCase); + /// /// Initializes a new instance of the class. /// @@ -170,6 +180,7 @@ namespace Emby.Server.Implementations.Localization { List list = []; Dictionary iso6392BtoTdict = new Dictionary(); + HashSet claimedCodes = new HashSet(StringComparer.OrdinalIgnoreCase); using var stream = _assembly.GetManifestResourceStream(CulturesPath); if (stream is null) @@ -223,6 +234,16 @@ namespace Emby.Server.Implementations.Localization iso6392BtoTdict.TryAdd(parts[1], parts[0]); } + // Variants (pt-br, es-419, zh-cn, ze, ...) share the ISO 639-2 code of their base + // language, but clients key their language pickers on ThreeLetterISOLanguageName and + // would collapse them onto one option. The first entry to claim a code keeps it, which + // is the same one FindLanguageInfo resolves that code to; the rest fall back to their + // own tag. + if (!claimedCodes.Add(parts[0]) && !string.IsNullOrEmpty(twoCharName)) + { + threeLetterNames = [twoCharName, .. threeLetterNames]; + } + list.Add(new CultureDto(name, displayname, twoCharName, threeLetterNames)); } @@ -244,6 +265,11 @@ namespace Emby.Server.Implementations.Localization language, static (lang, cultures) => { + if (_legacyLanguageAliases.TryGetValue(lang, out var alias)) + { + lang = alias; + } + // TODO language should ideally be a ReadOnlySpan but moq cannot mock ref structs for (var i = 0; i < cultures.Count; i++) { -- cgit v1.2.3