mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
Implement plugin i18n [WIP]
This commit is contained in:
@@ -3,25 +3,48 @@ using System.Linq;
|
||||
using System.Windows;
|
||||
using Wox.Core.i18n;
|
||||
using Wox.Core.Theme;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.UI
|
||||
{
|
||||
public class ResourceMerger
|
||||
{
|
||||
public static void ApplyResources()
|
||||
{
|
||||
Application.Current.Resources.MergedDictionaries.Clear();
|
||||
ApplyUIResources();
|
||||
ApplyPluginLanguages();
|
||||
}
|
||||
|
||||
private static void ApplyUIResources()
|
||||
{
|
||||
var UIResourceType = typeof(IUIResource);
|
||||
var UIResources = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.SelectMany(s => s.GetTypes())
|
||||
.Where(p => p.IsClass && !p.IsAbstract && UIResourceType.IsAssignableFrom(p));
|
||||
|
||||
Application.Current.Resources.MergedDictionaries.Clear();
|
||||
|
||||
foreach (var uiResource in UIResources)
|
||||
{
|
||||
Application.Current.Resources.MergedDictionaries.Add(
|
||||
((IUIResource)Activator.CreateInstance(uiResource)).GetResourceDictionary());
|
||||
}
|
||||
}
|
||||
|
||||
private static void ApplyPluginLanguages()
|
||||
{
|
||||
var pluginI18nType = typeof(IPluginI18n);
|
||||
var pluginI18ns = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.SelectMany(s => s.GetTypes())
|
||||
.Where(p => p.IsClass && !p.IsAbstract && pluginI18nType.IsAssignableFrom(p));
|
||||
|
||||
foreach (IPluginI18n pluginI18n in pluginI18ns)
|
||||
{
|
||||
string languageFile = InternationalizationManager.Internationalization.GetLanguageFile(pluginI18n.GetLanguagesFolder());
|
||||
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
|
||||
{
|
||||
Source = new Uri(languageFile, UriKind.Absolute)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user