mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
Localization: change to a provided service
This commit is contained in:
parent
aa99be6ccb
commit
efaa346d5e
3 changed files with 32 additions and 14 deletions
|
|
@ -65,7 +65,12 @@ internal sealed class Dalamud : IServiceType
|
|||
true, new FileInfo(Path.Combine(cacheDir.FullName, $"{this.StartInfo.GameVersion}.json")));
|
||||
}
|
||||
|
||||
ServiceManager.InitializeProvidedServices(this, fs, configuration, scanner);
|
||||
ServiceManager.InitializeProvidedServices(
|
||||
this,
|
||||
fs,
|
||||
configuration,
|
||||
scanner,
|
||||
Localization.FromAssets(info.AssetDirectory!, configuration.LanguageOverride));
|
||||
|
||||
// Set up FFXIVClientStructs
|
||||
this.SetupClientStructsResolver(cacheDir);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ using System.Linq;
|
|||
using System.Reflection;
|
||||
|
||||
using CheapLoc;
|
||||
using Dalamud.Configuration.Internal;
|
||||
|
||||
using Serilog;
|
||||
|
||||
|
|
@ -13,7 +12,7 @@ namespace Dalamud;
|
|||
/// <summary>
|
||||
/// Class handling localization.
|
||||
/// </summary>
|
||||
[ServiceManager.EarlyLoadedService]
|
||||
[ServiceManager.ProvidedService]
|
||||
public class Localization : IServiceType
|
||||
{
|
||||
/// <summary>
|
||||
|
|
@ -43,16 +42,6 @@ public class Localization : IServiceType
|
|||
this.assembly = Assembly.GetCallingAssembly();
|
||||
}
|
||||
|
||||
[ServiceManager.ServiceConstructor]
|
||||
private Localization(Dalamud dalamud, DalamudConfiguration configuration)
|
||||
: this(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "loc", "dalamud"), "dalamud_")
|
||||
{
|
||||
if (!string.IsNullOrEmpty(configuration.LanguageOverride))
|
||||
this.SetupWithLangCode(configuration.LanguageOverride);
|
||||
else
|
||||
this.SetupWithUiCulture();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for the <see cref="Localization.LocalizationChanged"/> event that occurs when the language is changed.
|
||||
/// </summary>
|
||||
|
|
@ -167,6 +156,22 @@ public class Localization : IServiceType
|
|||
Loc.ExportLocalizableForAssembly(this.assembly, ignoreInvalidFunctions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="Localization"/> class.
|
||||
/// </summary>
|
||||
/// <param name="assetDirectory">Path to Dalamud assets.</param>
|
||||
/// <param name="languageOverride">Optional language override.</param>
|
||||
/// <returns>A new instance.</returns>
|
||||
internal static Localization FromAssets(string assetDirectory, string? languageOverride)
|
||||
{
|
||||
var t = new Localization(Path.Combine(assetDirectory, "UIRes", "loc", "dalamud"), "dalamud_");
|
||||
if (!string.IsNullOrEmpty(languageOverride))
|
||||
t.SetupWithLangCode(languageOverride);
|
||||
else
|
||||
t.SetupWithUiCulture();
|
||||
return t;
|
||||
}
|
||||
|
||||
private string ReadLocData(string langCode)
|
||||
{
|
||||
if (this.useEmbedded)
|
||||
|
|
|
|||
|
|
@ -126,7 +126,13 @@ internal static class ServiceManager
|
|||
/// <param name="fs">Instance of <see cref="ReliableFileStorage"/>.</param>
|
||||
/// <param name="configuration">Instance of <see cref="DalamudConfiguration"/>.</param>
|
||||
/// <param name="scanner">Instance of <see cref="TargetSigScanner"/>.</param>
|
||||
public static void InitializeProvidedServices(Dalamud dalamud, ReliableFileStorage fs, DalamudConfiguration configuration, TargetSigScanner scanner)
|
||||
/// <param name="localization">Instance of <see cref="Localization"/>.</param>
|
||||
public static void InitializeProvidedServices(
|
||||
Dalamud dalamud,
|
||||
ReliableFileStorage fs,
|
||||
DalamudConfiguration configuration,
|
||||
TargetSigScanner scanner,
|
||||
Localization localization)
|
||||
{
|
||||
#if DEBUG
|
||||
lock (LoadedServices)
|
||||
|
|
@ -136,6 +142,7 @@ internal static class ServiceManager
|
|||
ProvideService(configuration);
|
||||
ProvideService(new ServiceContainer());
|
||||
ProvideService(scanner);
|
||||
ProvideService(localization);
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
@ -152,6 +159,7 @@ internal static class ServiceManager
|
|||
ProvideService(configuration);
|
||||
ProvideService(new ServiceContainer());
|
||||
ProvideService(scanner);
|
||||
ProvideService(localization);
|
||||
return;
|
||||
|
||||
void ProvideService<T>(T service) where T : IServiceType => Service<T>.Provide(service);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue