diff --git a/Plugins/Wox.Plugin.Program/Languages/en.xaml b/Plugins/Wox.Plugin.Program/Languages/en.xaml
index 4f5cb3aadc..d117108558 100644
--- a/Plugins/Wox.Plugin.Program/Languages/en.xaml
+++ b/Plugins/Wox.Plugin.Program/Languages/en.xaml
@@ -1,6 +1,7 @@
-
+
+ Delete
\ No newline at end of file
diff --git a/Plugins/Wox.Plugin.Program/ProgramSetting.xaml b/Plugins/Wox.Plugin.Program/ProgramSetting.xaml
index f0cdad9b91..d5036e915e 100644
--- a/Plugins/Wox.Plugin.Program/ProgramSetting.xaml
+++ b/Plugins/Wox.Plugin.Program/ProgramSetting.xaml
@@ -40,7 +40,7 @@
Indexing
-
+
diff --git a/Plugins/Wox.Plugin.Program/Programs.cs b/Plugins/Wox.Plugin.Program/Programs.cs
index 321bd075d4..ea525140f1 100644
--- a/Plugins/Wox.Plugin.Program/Programs.cs
+++ b/Plugins/Wox.Plugin.Program/Programs.cs
@@ -1,14 +1,16 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.IO;
using System.Linq;
using System.Reflection;
+using System.Windows;
using Wox.Infrastructure;
using Wox.Plugin.Program.ProgramSources;
namespace Wox.Plugin.Program
{
- public class Programs : ISettingProvider,IPlugin
+ public class Programs : ISettingProvider, IPlugin, IPluginI18n
{
private static object lockObject = new object();
private static List programs = new List();
@@ -76,7 +78,7 @@ namespace Wox.Plugin.Program
{
programs = ProgramCacheStorage.Instance.Programs;
}
- Debug.WriteLine(string.Format("Preload {0} programs from cache",programs.Count),"Wox");
+ Debug.WriteLine(string.Format("Preload {0} programs from cache", programs.Count), "Wox");
using (new Timeit("Program Index"))
{
IndexPrograms();
@@ -180,5 +182,10 @@ namespace Wox.Plugin.Program
}
#endregion
+
+ public string GetLanguagesFolder()
+ {
+ return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages");
+ }
}
}
diff --git a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj
index 0b2087ce8f..c72b51267d 100644
--- a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj
+++ b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj
@@ -1,126 +1,126 @@
-
-
-
-
- Debug
- AnyCPU
- {FDB3555B-58EF-4AE6-B5F1-904719637AB4}
- Library
- Properties
- Wox.Plugin.Program
- Wox.Plugin.Program
- v3.5
- 512
- ..\..\
- true
-
-
- true
- full
- false
- ..\..\Output\Debug\Plugins\Wox.Plugin.Program\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
- ..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll
-
-
- False
- ..\..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ProgramSetting.xaml
-
-
-
-
-
-
-
-
- ProgramSuffixes.xaml
-
-
-
-
-
-
-
- PreserveNewest
-
-
-
-
- PreserveNewest
-
-
- MSBuild:Compile
- Designer
- PreserveNewest
-
-
-
-
- MSBuild:Compile
- Designer
-
-
- MSBuild:Compile
- Designer
-
-
-
-
- {4fd29318-a8ab-4d8f-aa47-60bc241b8da3}
- Wox.Infrastructure
-
-
- {8451ecdd-2ea4-4966-bb0a-7bbc40138e80}
- Wox.Plugin
-
-
-
-
-
-
-
- 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。
-
-
-
-
+
+
+
+
+ Debug
+ AnyCPU
+ {FDB3555B-58EF-4AE6-B5F1-904719637AB4}
+ Library
+ Properties
+ Wox.Plugin.Program
+ Wox.Plugin.Program
+ v3.5
+ 512
+ ..\..\
+ true
+
+
+ true
+ full
+ false
+ ..\..\Output\Debug\Plugins\Wox.Plugin.Program\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ ..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll
+
+
+ False
+ ..\..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ProgramSetting.xaml
+
+
+
+
+
+
+
+
+ ProgramSuffixes.xaml
+
+
+
+
+
+
+
+ PreserveNewest
+
+
+
+
+ PreserveNewest
+
+
+ MSBuild:Compile
+ Designer
+ PreserveNewest
+
+
+
+
+ MSBuild:Compile
+ Designer
+
+
+ MSBuild:Compile
+ Designer
+
+
+
+
+ {4fd29318-a8ab-4d8f-aa47-60bc241b8da3}
+ Wox.Infrastructure
+
+
+ {8451ecdd-2ea4-4966-bb0a-7bbc40138e80}
+ Wox.Plugin
+
+
+
+
+
+
+
+ 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。
+
+
+
+
\ No newline at end of file
diff --git a/Wox.Core/UI/IUIResource.cs b/Wox.Core/UI/IUIResource.cs
index b4940ee39b..a1e398a25c 100644
--- a/Wox.Core/UI/IUIResource.cs
+++ b/Wox.Core/UI/IUIResource.cs
@@ -3,13 +3,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
+using Wox.Core.i18n;
namespace Wox.Core.UI
{
///
/// Object implement this interface will have the ability to has its own UI styles
///
- interface IUIResource
+ public interface IUIResource
{
ResourceDictionary GetResourceDictionary();
}
diff --git a/Wox.Core/UI/ResourceMerger.cs b/Wox.Core/UI/ResourceMerger.cs
index 5f6ee7e60c..60e34fdeb6 100644
--- a/Wox.Core/UI/ResourceMerger.cs
+++ b/Wox.Core/UI/ResourceMerger.cs
@@ -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)
+ });
+ }
+ }
}
-}
+}
\ No newline at end of file
diff --git a/Wox.Core/i18n/IInternationalization.cs b/Wox.Core/i18n/IInternationalization.cs
index cbf43364c4..b74af99be1 100644
--- a/Wox.Core/i18n/IInternationalization.cs
+++ b/Wox.Core/i18n/IInternationalization.cs
@@ -11,6 +11,15 @@ namespace Wox.Core.i18n
string GetTranslation(string key);
+ ///
+ /// Get language file for current user selected language
+ /// if couldn't find the current selected language file, it will first try to load en.xaml
+ /// if en.xaml couldn't find, it will pick up first *.xaml file
+ ///
+ ///
+ ///
+ string GetLanguageFile(string folder);
+
void ChangeLanguage(Language language);
void ChangeLanguage(string languageCode);
diff --git a/Wox.Core/i18n/Internationalization.cs b/Wox.Core/i18n/Internationalization.cs
index 90342c7343..fdb51e1c35 100644
--- a/Wox.Core/i18n/Internationalization.cs
+++ b/Wox.Core/i18n/Internationalization.cs
@@ -14,28 +14,24 @@ namespace Wox.Core.i18n
{
public class Internationalization : IInternationalization, IUIResource
{
- private static List languageDirectories = new List();
+ private static string DefaultLanguageDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages");
static Internationalization()
{
- languageDirectories.Add(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"));
MakesureThemeDirectoriesExist();
}
private static void MakesureThemeDirectoriesExist()
{
- foreach (string pluginDirectory in languageDirectories)
+ if (!Directory.Exists(DefaultLanguageDirectory))
{
- if (!Directory.Exists(pluginDirectory))
+ try
{
- try
- {
- Directory.CreateDirectory(pluginDirectory);
- }
- catch (System.Exception e)
- {
- Log.Error(e.Message);
- }
+ Directory.CreateDirectory(DefaultLanguageDirectory);
+ }
+ catch (System.Exception e)
+ {
+ Log.Error(e.Message);
}
}
}
@@ -59,7 +55,7 @@ namespace Wox.Core.i18n
public void ChangeLanguage(Language language)
{
- if(language == null) throw new WoxI18nException("language can't be null");
+ if (language == null) throw new WoxI18nException("language can't be null");
string path = GetLanguagePath(language);
if (string.IsNullOrEmpty(path))
@@ -80,7 +76,7 @@ namespace Wox.Core.i18n
{
return new ResourceDictionary
{
- Source = new Uri(GetLanguagePath(UserSettingStorage.Instance.Language), UriKind.Absolute)
+ Source = new Uri(GetLanguageFile(DefaultLanguageDirectory), UriKind.Absolute)
};
}
@@ -115,16 +111,44 @@ namespace Wox.Core.i18n
private string GetLanguagePath(Language language)
{
- foreach (string directory in languageDirectories)
+ string path = Path.Combine(DefaultLanguageDirectory, language.LanguageCode + ".xaml");
+ if (File.Exists(path))
{
- string path = Path.Combine(directory, language.LanguageCode + ".xaml");
- if (File.Exists(path))
- {
- return path;
- }
+ return path;
}
return string.Empty;
}
+
+
+ public string GetLanguageFile(string folder)
+ {
+ if (!Directory.Exists(folder)) return string.Empty;
+
+ string path = Path.Combine(folder, UserSettingStorage.Instance.Language + ".xaml");
+ if (File.Exists(path))
+ {
+ return path;
+ }
+ else
+ {
+ string english = Path.Combine(folder, "en.xaml");
+ if (File.Exists(english))
+ {
+ return english;
+ }
+ else
+ {
+ string file = Directory.GetFiles(folder).FirstOrDefault(o => o.EndsWith("xaml"));
+ if (string.IsNullOrEmpty(file))
+ {
+ throw new WoxI18nException(string.Format("Couldn't find language file from:{0}, current selected language:{1}"));
+ }
+
+ return Path.Combine(folder, file);
+ }
+ }
+
+ }
}
}
diff --git a/Wox.Infrastructure/Storage/BinaryStorage.cs b/Wox.Infrastructure/Storage/BinaryStorage.cs
index 4302acbd96..7561ba1149 100644
--- a/Wox.Infrastructure/Storage/BinaryStorage.cs
+++ b/Wox.Infrastructure/Storage/BinaryStorage.cs
@@ -31,19 +31,26 @@ namespace Wox.Infrastructure.Storage
{
using (FileStream fileStream = new FileStream(ConfigPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
- BinaryFormatter binaryFormatter = new BinaryFormatter
+ if (fileStream.Length > 0)
{
- AssemblyFormat = FormatterAssemblyStyle.Simple
- };
- serializedObject = binaryFormatter.Deserialize(fileStream) as T;
- if (serializedObject == null)
+ BinaryFormatter binaryFormatter = new BinaryFormatter
+ {
+ AssemblyFormat = FormatterAssemblyStyle.Simple
+ };
+ serializedObject = binaryFormatter.Deserialize(fileStream) as T;
+ if (serializedObject == null)
+ {
+ serializedObject = LoadDefault();
+#if (DEBUG)
+ {
+ throw new Exception("deserialize failed");
+ }
+#endif
+ }
+ }
+ else
{
serializedObject = LoadDefault();
-#if (DEBUG)
- {
- throw new Exception("deserialize failed");
- }
-#endif
}
}
}
diff --git a/Wox.Plugin/IPluginI18n.cs b/Wox.Plugin/IPluginI18n.cs
new file mode 100644
index 0000000000..cb13dd02bb
--- /dev/null
+++ b/Wox.Plugin/IPluginI18n.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+namespace Wox.Plugin
+{
+ ///
+ /// Represent plugins that support internationalization
+ ///
+ public interface IPluginI18n
+ {
+ string GetLanguagesFolder();
+ }
+}
diff --git a/Wox.Plugin/Wox.Plugin.csproj b/Wox.Plugin/Wox.Plugin.csproj
index d915ddd7bc..8f7aa59418 100644
--- a/Wox.Plugin/Wox.Plugin.csproj
+++ b/Wox.Plugin/Wox.Plugin.csproj
@@ -47,6 +47,7 @@
+