mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-30 13:56:31 +01:00
feat(i18n): transliterate item name before sorting (#11172)
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Diacritics" />
|
||||
<PackageReference Include="ICU4N.Transliterator" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using ICU4N.Text;
|
||||
|
||||
namespace Jellyfin.Extensions
|
||||
{
|
||||
@@ -8,6 +9,9 @@ namespace Jellyfin.Extensions
|
||||
/// </summary>
|
||||
public static partial class StringExtensions
|
||||
{
|
||||
private static readonly Lazy<Transliterator> _transliterator = new(() => Transliterator.GetInstance(
|
||||
"Any-Latin; Latin-Ascii; Lower; NFD; [:Nonspacing Mark:] Remove; [:Punctuation:] Remove;"));
|
||||
|
||||
// Matches non-conforming unicode chars
|
||||
// https://mnaoumov.wordpress.com/2014/06/14/stripping-invalid-characters-from-utf-16-strings/
|
||||
|
||||
@@ -96,5 +100,15 @@ namespace Jellyfin.Extensions
|
||||
|
||||
return haystack[(pos + 1)..];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a transliterated string which only contain ascii characters.
|
||||
/// </summary>
|
||||
/// <param name="text">The string to act on.</param>
|
||||
/// <returns>The transliterated string.</returns>
|
||||
public static string Transliterated(this string text)
|
||||
{
|
||||
return _transliterator.Value.Transliterate(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user