chore: use ResourcesMerge for loc
This commit is contained in:
parent
accb06d32f
commit
8010d0fab6
|
@ -1,4 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
||||
<Resourcer/>
|
||||
<ResourcesMerge/>
|
||||
</Weavers>
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
<ItemGroup>
|
||||
<InputAssemblies Include="$(OutputPath)\NoSoliciting.dll"/>
|
||||
<InputAssemblies Include="$(OutputPath)\NoSoliciting.Interface.dll"/>
|
||||
<InputAssemblies Include="$(OutputPath)\*\NoSoliciting.resources.dll"/>
|
||||
<InputAssemblies Include="$(OutputPath)\J*.dll"/>
|
||||
<InputAssemblies Include="$(OutputPath)\M*.dll"/>
|
||||
<InputAssemblies Include="$(OutputPath)\S*.dll"/>
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
<PackageReference Include="JKang.IpcServiceFramework.Client.NamedPipe" Version="3.1.0"/>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1"/>
|
||||
<PackageReference Include="Resourcer.Fody" Version="1.8.0" PrivateAssets="all"/>
|
||||
<PackageReference Include="ResourcesMerge.Fody" Version="1.0.1"/>
|
||||
<PackageReference Include="XivCommon" Version="1.5.0"/>
|
||||
<PackageReference Include="YamlDotNet" Version="11.1.1"/>
|
||||
</ItemGroup>
|
||||
|
|
|
@ -48,7 +48,6 @@ namespace NoSoliciting {
|
|||
this.Config = this.Interface.GetPluginConfig() as PluginConfiguration ?? new PluginConfiguration();
|
||||
this.Config.Initialise(this.Interface);
|
||||
|
||||
Util.PreloadEmbeddedResources(this.GetType().Assembly, Language.ResourceManager, "NoSoliciting.Resources.Language.");
|
||||
this.ConfigureLanguage();
|
||||
this.Interface.OnLanguageChanged += this.OnLanguageUpdate;
|
||||
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
|
||||
namespace NoSoliciting {
|
||||
internal static class Util {
|
||||
internal static void PreloadEmbeddedResources(Assembly resourceAssembly, ResourceManager resourceManager, string resourcesPrefix, string resourcesExtension = ".resources") {
|
||||
// get loaded resource sets from resource manager
|
||||
if ((
|
||||
resourceManager.GetType().GetField("_resourceSets", BindingFlags.Instance | BindingFlags.NonPublic) ??
|
||||
// ReSharper disable once PossibleNullReferenceException
|
||||
resourceManager.GetType().GetField("ResourceSets", BindingFlags.Instance | BindingFlags.NonPublic)
|
||||
).GetValue(resourceManager) is not IDictionary resourceSetByCulture) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var embeddedResourceName in resourceAssembly.GetManifestResourceNames()) {
|
||||
if (!embeddedResourceName.StartsWith(resourcesPrefix, StringComparison.Ordinal) ||
|
||||
!embeddedResourceName.EndsWith(resourcesExtension, StringComparison.Ordinal)) {
|
||||
continue; // not localized resource
|
||||
}
|
||||
|
||||
var locale = embeddedResourceName.Substring(resourcesPrefix.Length, Math.Max(0, embeddedResourceName.Length - resourcesPrefix.Length - resourcesExtension.Length));
|
||||
if (string.IsNullOrEmpty(locale)) {
|
||||
continue; // default locale
|
||||
}
|
||||
|
||||
var resourceStream = resourceAssembly.GetManifestResourceStream(embeddedResourceName);
|
||||
if (resourceStream == null) {
|
||||
continue; // no resource stream
|
||||
}
|
||||
|
||||
var resourceSet = new System.Resources.ResourceSet(resourceStream);
|
||||
var culture = CultureInfo.GetCultureInfo(locale);
|
||||
|
||||
var key = resourceSetByCulture is Hashtable
|
||||
? (object) culture
|
||||
: culture.Name;
|
||||
|
||||
// remove any old resources if there somehow are any
|
||||
if (resourceSetByCulture.Contains(key)) {
|
||||
resourceSetByCulture.Remove(key);
|
||||
}
|
||||
|
||||
resourceSetByCulture.Add(key, resourceSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue