mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
Fix ResourceMerger
1. Fix duplication for loading resource. 2. Fix null reference when plugin is not loaded. 3. speedup.
This commit is contained in:
@@ -14,7 +14,8 @@ namespace Wox.Core.i18n
|
||||
{
|
||||
public class Internationalization : IInternationalization, IUIResource
|
||||
{
|
||||
private static string DefaultLanguageDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages");
|
||||
public const string DirectoryName = "Languages";
|
||||
private static readonly string DefaultDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), DirectoryName);
|
||||
|
||||
static Internationalization()
|
||||
{
|
||||
@@ -23,11 +24,11 @@ namespace Wox.Core.i18n
|
||||
|
||||
private static void MakesureThemeDirectoriesExist()
|
||||
{
|
||||
if (!Directory.Exists(DefaultLanguageDirectory))
|
||||
if (!Directory.Exists(DefaultDirectory))
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(DefaultLanguageDirectory);
|
||||
Directory.CreateDirectory(DefaultDirectory);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
@@ -69,15 +70,14 @@ namespace Wox.Core.i18n
|
||||
|
||||
UserSettingStorage.Instance.Language = language.LanguageCode;
|
||||
UserSettingStorage.Instance.Save();
|
||||
ResourceMerger.ApplyResources();
|
||||
UpdateAllPluginMetadataTranslations();
|
||||
ResourceMerger.ApplyLanguageResources();
|
||||
}
|
||||
|
||||
public ResourceDictionary GetResourceDictionary()
|
||||
{
|
||||
return new ResourceDictionary
|
||||
{
|
||||
Source = new Uri(GetLanguageFile(DefaultLanguageDirectory), UriKind.Absolute)
|
||||
Source = new Uri(GetLanguageFile(DefaultDirectory), UriKind.Absolute)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -111,15 +111,6 @@ namespace Wox.Core.i18n
|
||||
}
|
||||
|
||||
|
||||
internal void UpdateAllPluginMetadataTranslations()
|
||||
{
|
||||
List<KeyValuePair<PluginPair, IPluginI18n>> plugins = AssemblyHelper.LoadPluginInterfaces<IPluginI18n>();
|
||||
foreach (var plugin in plugins)
|
||||
{
|
||||
UpdatePluginMetadataTranslations(plugin.Key);
|
||||
}
|
||||
}
|
||||
|
||||
internal void UpdatePluginMetadataTranslations(PluginPair pluginPair)
|
||||
{
|
||||
var pluginI18n = pluginPair.Plugin as IPluginI18n;
|
||||
@@ -142,7 +133,7 @@ namespace Wox.Core.i18n
|
||||
|
||||
private string GetLanguagePath(Language language)
|
||||
{
|
||||
string path = Path.Combine(DefaultLanguageDirectory, language.LanguageCode + ".xaml");
|
||||
string path = Path.Combine(DefaultDirectory, language.LanguageCode + ".xaml");
|
||||
if (File.Exists(path))
|
||||
{
|
||||
return path;
|
||||
|
||||
Reference in New Issue
Block a user