diff --git a/src/Jellyfin.Extensions/StringExtensions.cs b/src/Jellyfin.Extensions/StringExtensions.cs index 8cfebd594dc..4b9677d9f44 100644 --- a/src/Jellyfin.Extensions/StringExtensions.cs +++ b/src/Jellyfin.Extensions/StringExtensions.cs @@ -9,8 +9,21 @@ namespace Jellyfin.Extensions /// public static partial class StringExtensions { - private static readonly Lazy _transliterator = new(() => Transliterator.GetInstance( - "Any-Latin; Latin-Ascii; Lower; NFD; [:Nonspacing Mark:] Remove; [:Punctuation:] Remove;")); + private static readonly Lazy _transliteratorId = new(() => + Environment.GetEnvironmentVariable("JELLYFIN_TRANSLITERATOR_ID") + ?? "Any-Latin; Latin-Ascii; Lower; NFD; [:Nonspacing Mark:] Remove; [:Punctuation:] Remove;"); + + private static readonly Lazy _transliterator = new(() => + { + try + { + return Transliterator.GetInstance(_transliteratorId.Value); + } + catch (ArgumentException) + { + return null; + } + }); // Matches non-conforming unicode chars // https://mnaoumov.wordpress.com/2014/06/14/stripping-invalid-characters-from-utf-16-strings/ @@ -108,7 +121,7 @@ public static ReadOnlySpan RightPart(this ReadOnlySpan haystack, cha /// The transliterated string. public static string Transliterated(this string text) { - return _transliterator.Value.Transliterate(text); + return (_transliterator.Value is null) ? text : _transliterator.Value.Transliterate(text); } } }