diff options
| author | Shadowghost <Shadowghost@users.noreply.github.com> | 2026-11-20 07:25:01 -0500 |
|---|---|---|
| committer | Cody Robibero <cody@robibe.ro> | 2026-11-20 07:25:01 -0500 |
| commit | a2ca4a7b84e89957547a9fb04a190b139c86e72f (patch) | |
| tree | 091f14663fde79259a0539e25a73c8893264c1fb /Emby.Server.Implementations/Localization/LocalizationManager.cs | |
| parent | 511f1ef882d594df64810d2c36b59ad381fd6e17 (diff) | |
Backport pull request #18072 from jellyfin/release-12.z
Keep language variants distinguishable
Original-merge: 060233101dc336560b2f97d251fe7a9f8241b763
Merged-by: crobibero <cody@robibe.ro>
Backported-by: Cody Robibero <cody@robibe.ro>
Diffstat (limited to 'Emby.Server.Implementations/Localization/LocalizationManager.cs')
| -rw-r--r-- | Emby.Server.Implementations/Localization/LocalizationManager.cs | 26 |
1 files changed, 26 insertions, 0 deletions
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<string, string> _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<string, string> _legacyLanguageAliases = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) + { + { "pob", "pt-br" }, + { "pb", "pt-br" }, + { "pop", "pt-pt" }, + { "es-mx", "es-419" }, + }.ToFrozenDictionary(StringComparer.OrdinalIgnoreCase); + /// <summary> /// Initializes a new instance of the <see cref="LocalizationManager" /> class. /// </summary> @@ -170,6 +180,7 @@ namespace Emby.Server.Implementations.Localization { List<CultureDto> list = []; Dictionary<string, string> iso6392BtoTdict = new Dictionary<string, string>(); + HashSet<string> claimedCodes = new HashSet<string>(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++) { |
