fix(loc): make localisation actually work
This commit is contained in:
parent
026a6a760d
commit
228b52ca3d
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
||||
<Resourcer/>
|
||||
<ResourcesMerge/>
|
||||
<ILMerge ExcludeResources="^NAudio\.WinForms\..+"/>
|
||||
</Weavers>
|
||||
|
|
|
@ -46,10 +46,10 @@
|
|||
<PackageReference Include="DalamudPackager" Version="1.2.1"/>
|
||||
<PackageReference Include="Fody" Version="6.5.1" PrivateAssets="all"/>
|
||||
<PackageReference Include="ILMerge.Fody" Version="1.16.0" PrivateAssets="all"/>
|
||||
<PackageReference Include="ILRepack.Lib.MSBuild.Task" Version="2.0.18.2"/>
|
||||
<PackageReference Include="NAudio" Version="2.0.0"/>
|
||||
<PackageReference Include="Resourcer.Fody" Version="1.8.0" PrivateAssets="all"/>
|
||||
<PackageReference Include="XivCommon" Version="1.2.0"/>
|
||||
<PackageReference Include="ResourcesMerge.Fody" Version="1.0.1" PrivateAssets="all"/>
|
||||
<PackageReference Include="XivCommon" Version="1.5.0"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="Resources\Language.Designer.cs">
|
||||
|
@ -58,17 +58,4 @@
|
|||
<DependentUpon>Language.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Target Name="MergeLocalisedResources" AfterTargets="Build">
|
||||
<ItemGroup>
|
||||
<InputAssemblies Include="$(OutputPath)\$(AssemblyName).dll"/>
|
||||
<InputAssemblies Include="$(OutputPath)\*\$(AssemblyName).resources.dll"/>
|
||||
</ItemGroup>
|
||||
<ILRepack
|
||||
Parallel="true"
|
||||
InputAssemblies="@(InputAssemblies)"
|
||||
LibraryPath="$(OutputPath);$(AppData)\XIVLauncher\addon\Hooks\dev"
|
||||
TargetKind="Dll"
|
||||
OutputFile="$(OutputPath)\$(AssemblyName).dll"
|
||||
/>
|
||||
</Target>
|
||||
</Project>
|
||||
|
|
|
@ -28,7 +28,6 @@ namespace PeepingTom {
|
|||
this.Watcher = new TargetWatcher(this);
|
||||
this.Ui = new PluginUi(this);
|
||||
|
||||
Util.PreLoadResourcesFromMainAssembly("PeepingTom.Resources.Language.");
|
||||
OnLanguageChange(this.Interface.UiLanguage);
|
||||
this.Interface.OnLanguageChanged += OnLanguageChange;
|
||||
|
||||
|
|
|
@ -1,50 +1,4 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
|
||||
namespace PeepingTom {
|
||||
internal static class Util {
|
||||
internal static void PreLoadResourcesFromMainAssembly(string resourcesPrefix, string resourcesExtension = ".resources") {
|
||||
// get loaded resource sets from resource manager
|
||||
var resourceManager = Resources.Language.ResourceManager;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
var resourceAssembly = typeof(PeepingTomPlugin).Assembly; // get assembly with localization resources
|
||||
foreach (var embeddedResourceName in resourceAssembly.GetManifestResourceNames()) {
|
||||
if (embeddedResourceName.StartsWith(resourcesPrefix, StringComparison.Ordinal) == false ||
|
||||
embeddedResourceName.EndsWith(resourcesExtension, StringComparison.Ordinal) == false) {
|
||||
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);
|
||||
if (resourceSetByCulture is Hashtable) {
|
||||
resourceSetByCulture.Add(culture, resourceSet);
|
||||
} else {
|
||||
resourceSetByCulture.Add(culture.Name, resourceSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace PeepingTom {
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1716:Identifiers should not match keywords")]
|
||||
public class Optional<T> where T : class {
|
||||
public bool Present { get; }
|
||||
|
|
Loading…
Reference in New Issue