mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-20 00:55:13 +01:00
Reworked LocalizationManager to load data async
This commit is contained in:
@@ -110,9 +110,7 @@ using MediaBrowser.XbmcMetadata.Providers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ServiceStack;
|
||||
using ServiceStack.Text.Jsv;
|
||||
using StringExtensions = MediaBrowser.Controller.Extensions.StringExtensions;
|
||||
using X509Certificate = System.Security.Cryptography.X509Certificates.X509Certificate;
|
||||
using UtfUnknown;
|
||||
|
||||
namespace Emby.Server.Implementations
|
||||
{
|
||||
@@ -303,7 +301,7 @@ namespace Emby.Server.Implementations
|
||||
|
||||
private ILiveTvManager LiveTvManager { get; set; }
|
||||
|
||||
public ILocalizationManager LocalizationManager { get; set; }
|
||||
public LocalizationManager LocalizationManager { get; set; }
|
||||
|
||||
private IEncodingManager EncodingManager { get; set; }
|
||||
private IChannelManager ChannelManager { get; set; }
|
||||
@@ -704,7 +702,7 @@ namespace Emby.Server.Implementations
|
||||
}
|
||||
}
|
||||
|
||||
public void Init()
|
||||
public async Task Init()
|
||||
{
|
||||
HttpPort = ServerConfigurationManager.Configuration.HttpServerPortNumber;
|
||||
HttpsPort = ServerConfigurationManager.Configuration.HttpsPortNumber;
|
||||
@@ -734,7 +732,7 @@ namespace Emby.Server.Implementations
|
||||
|
||||
SetHttpLimit();
|
||||
|
||||
RegisterResources();
|
||||
await RegisterResources();
|
||||
|
||||
FindParts();
|
||||
}
|
||||
@@ -749,7 +747,7 @@ namespace Emby.Server.Implementations
|
||||
/// <summary>
|
||||
/// Registers resources that classes will depend on
|
||||
/// </summary>
|
||||
protected void RegisterResources()
|
||||
protected async Task RegisterResources()
|
||||
{
|
||||
RegisterSingleInstance(ConfigurationManager);
|
||||
RegisterSingleInstance<IApplicationHost>(this);
|
||||
@@ -810,9 +808,9 @@ namespace Emby.Server.Implementations
|
||||
IAssemblyInfo assemblyInfo = new AssemblyInfo();
|
||||
RegisterSingleInstance(assemblyInfo);
|
||||
|
||||
LocalizationManager = new LocalizationManager(ServerConfigurationManager, FileSystemManager, JsonSerializer, LoggerFactory, assemblyInfo, new TextLocalizer());
|
||||
StringExtensions.LocalizationManager = LocalizationManager;
|
||||
RegisterSingleInstance(LocalizationManager);
|
||||
LocalizationManager = new LocalizationManager(ServerConfigurationManager, FileSystemManager, JsonSerializer, LoggerFactory);
|
||||
await LocalizationManager.LoadAll();
|
||||
RegisterSingleInstance<ILocalizationManager>(LocalizationManager);
|
||||
|
||||
BlurayExaminer = new BdInfoExaminer(FileSystemManager);
|
||||
RegisterSingleInstance(BlurayExaminer);
|
||||
|
||||
@@ -322,18 +322,18 @@ namespace Emby.Server.Implementations.Library
|
||||
|
||||
private string[] NormalizeLanguage(string language)
|
||||
{
|
||||
if (language != null)
|
||||
if (language == null)
|
||||
{
|
||||
var culture = _localizationManager.FindLanguageInfo(language);
|
||||
if (culture != null)
|
||||
{
|
||||
return culture.ThreeLetterISOLanguageNames;
|
||||
}
|
||||
|
||||
return new string[] { language };
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
|
||||
return Array.Empty<string>();
|
||||
var culture = _localizationManager.FindLanguageInfo(language);
|
||||
if (culture != null)
|
||||
{
|
||||
return culture.ThreeLetterISOLanguageNames;
|
||||
}
|
||||
|
||||
return new string[] { language };
|
||||
}
|
||||
|
||||
private void SetDefaultSubtitleStreamIndex(MediaSourceInfo source, UserItemData userData, User user, bool allowRememberingSelection)
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,63 +0,0 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Emby.Server.Implementations.Localization
|
||||
{
|
||||
public class TextLocalizer : ITextLocalizer
|
||||
{
|
||||
public string RemoveDiacritics(string text)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
|
||||
var chars = Normalize(text, NormalizationForm.FormD)
|
||||
.Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) != UnicodeCategory.NonSpacingMark);
|
||||
|
||||
return Normalize(string.Concat(chars), NormalizationForm.FormC);
|
||||
}
|
||||
|
||||
private static string Normalize(string text, NormalizationForm form, bool stripStringOnFailure = true)
|
||||
{
|
||||
if (stripStringOnFailure)
|
||||
{
|
||||
try
|
||||
{
|
||||
return text.Normalize(form);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// will throw if input contains invalid unicode chars
|
||||
// https://mnaoumov.wordpress.com/2014/06/14/stripping-invalid-characters-from-utf-16-strings/
|
||||
text = StripInvalidUnicodeCharacters(text);
|
||||
return Normalize(text, form, false);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return text.Normalize(form);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// if it still fails, return the original text
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
private static string StripInvalidUnicodeCharacters(string str)
|
||||
{
|
||||
var invalidCharactersRegex = new Regex("([\ud800-\udbff](?![\udc00-\udfff]))|((?<![\ud800-\udbff])[\udc00-\udfff])");
|
||||
return invalidCharactersRegex.Replace(str, "");
|
||||
}
|
||||
|
||||
public string NormalizeFormKD(string text)
|
||||
{
|
||||
return text.Normalize(NormalizationForm.FormKD);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user