diff --git a/Plugins/Wox.Plugin.CMD/CMD.cs b/Plugins/Wox.Plugin.CMD/CMD.cs index da5877c67f..f2ed269ee7 100644 --- a/Plugins/Wox.Plugin.CMD/CMD.cs +++ b/Plugins/Wox.Plugin.CMD/CMD.cs @@ -213,6 +213,16 @@ namespace Wox.Plugin.CMD return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"); } + public string GetTranslatedPluginTitle() + { + return context.API.GetTranslation("wox_plugin_cmd_plugin_name"); + } + + public string GetTranslatedPluginDescription() + { + return context.API.GetTranslation("wox_plugin_cmd_plugin_description"); + } + public bool IsInstantQuery(string query) { if (query.StartsWith(">")) return true; diff --git a/Plugins/Wox.Plugin.CMD/Languages/en.xaml b/Plugins/Wox.Plugin.CMD/Languages/en.xaml index 309a4867db..a37ee02a93 100644 --- a/Plugins/Wox.Plugin.CMD/Languages/en.xaml +++ b/Plugins/Wox.Plugin.CMD/Languages/en.xaml @@ -4,5 +4,7 @@ Replace Win+R Do not close Command Prompt after command execution + Shell + Provide executing commands from Wox. Commands should start with > \ No newline at end of file diff --git a/Plugins/Wox.Plugin.CMD/Languages/zh-cn.xaml b/Plugins/Wox.Plugin.CMD/Languages/zh-cn.xaml index 0847dda6ce..9693f5f3cc 100644 --- a/Plugins/Wox.Plugin.CMD/Languages/zh-cn.xaml +++ b/Plugins/Wox.Plugin.CMD/Languages/zh-cn.xaml @@ -1,8 +1,10 @@ - - - 替换 Win+R - 执行后不关闭命令窗口 - + + + 替换 Win+R + 执行后不关闭命令窗口 + 命令行 + 提供从Wox中执行命令行的能力,命令应该以>开头 + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.CMD/Languages/zh-tw.xaml b/Plugins/Wox.Plugin.CMD/Languages/zh-tw.xaml index 8ac28c3639..7d318ff0bc 100644 --- a/Plugins/Wox.Plugin.CMD/Languages/zh-tw.xaml +++ b/Plugins/Wox.Plugin.CMD/Languages/zh-tw.xaml @@ -1,8 +1,10 @@ - - - 替換 Win+R - 執行後不關閉命令窗口 - + + + 替換 Win+R + 執行後不關閉命令窗口 + 命令行 + 提供從Wox中執行命令行的能力,命令應該以>開頭 + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Everything/Languages/en.xaml b/Plugins/Wox.Plugin.Everything/Languages/en.xaml index 18c583ae0e..abb592bb7f 100644 --- a/Plugins/Wox.Plugin.Everything/Languages/en.xaml +++ b/Plugins/Wox.Plugin.Everything/Languages/en.xaml @@ -7,5 +7,8 @@ Copied Can't start {0} Open containing folder + + Everything + Search disk files using Everything \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Everything/Languages/zh-cn.xaml b/Plugins/Wox.Plugin.Everything/Languages/zh-cn.xaml index 50d3f189c1..d9f3dd7092 100644 --- a/Plugins/Wox.Plugin.Everything/Languages/zh-cn.xaml +++ b/Plugins/Wox.Plugin.Everything/Languages/zh-cn.xaml @@ -8,4 +8,7 @@ 不能启动 {0} 打开所属文件夹 + Everything + 利用Everything搜索磁盘文件 + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Everything/Languages/zh-tw.xaml b/Plugins/Wox.Plugin.Everything/Languages/zh-tw.xaml index c61e4ffec7..46aac0db99 100644 --- a/Plugins/Wox.Plugin.Everything/Languages/zh-tw.xaml +++ b/Plugins/Wox.Plugin.Everything/Languages/zh-tw.xaml @@ -8,4 +8,6 @@ 不能啟動 {0} 打開所屬文件夾 + Everything + 利用Everything搜索磁盤文件 \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Everything/Main.cs b/Plugins/Wox.Plugin.Everything/Main.cs index 86862097c0..8e36ec9257 100644 --- a/Plugins/Wox.Plugin.Everything/Main.cs +++ b/Plugins/Wox.Plugin.Everything/Main.cs @@ -211,5 +211,15 @@ namespace Wox.Plugin.Everything { return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"); } + + public string GetTranslatedPluginTitle() + { + return context.API.GetTranslation("wox_plugin_everything_plugin_name"); + } + + public string GetTranslatedPluginDescription() + { + return context.API.GetTranslation("wox_plugin_everything_plugin_description"); + } } } diff --git a/Plugins/Wox.Plugin.Everything/Wox.Plugin.Everything.csproj b/Plugins/Wox.Plugin.Everything/Wox.Plugin.Everything.csproj index 6eef11c31b..0c677c0d26 100644 --- a/Plugins/Wox.Plugin.Everything/Wox.Plugin.Everything.csproj +++ b/Plugins/Wox.Plugin.Everything/Wox.Plugin.Everything.csproj @@ -41,6 +41,7 @@ ..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll + diff --git a/Plugins/Wox.Plugin.Folder/FolderPlugin.cs b/Plugins/Wox.Plugin.Folder/FolderPlugin.cs index 7e7c641021..622acac0d3 100644 --- a/Plugins/Wox.Plugin.Folder/FolderPlugin.cs +++ b/Plugins/Wox.Plugin.Folder/FolderPlugin.cs @@ -220,5 +220,15 @@ namespace Wox.Plugin.Folder { return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"); } + + public string GetTranslatedPluginTitle() + { + return context.API.GetTranslation("wox_plugin_folder_plugin_name"); + } + + public string GetTranslatedPluginDescription() + { + return context.API.GetTranslation("wox_plugin_folder_plugin_description"); + } } } \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Folder/Languages/en.xaml b/Plugins/Wox.Plugin.Folder/Languages/en.xaml index f9bbd6b3b9..cee4e4d808 100644 --- a/Plugins/Wox.Plugin.Folder/Languages/en.xaml +++ b/Plugins/Wox.Plugin.Folder/Languages/en.xaml @@ -8,5 +8,8 @@ Folder Path Please select a folder link Are your sure to delete {0}? - + + Folder + Open favorite folder from wox directorily + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Folder/Languages/zh-cn.xaml b/Plugins/Wox.Plugin.Folder/Languages/zh-cn.xaml index 559b9f4906..01b435ec41 100644 --- a/Plugins/Wox.Plugin.Folder/Languages/zh-cn.xaml +++ b/Plugins/Wox.Plugin.Folder/Languages/zh-cn.xaml @@ -1,12 +1,15 @@ - - - 删除 - 编辑 - 添加 - 文件夹路径 - 请选择一个文件夹 - 你确定要删除{0}吗? - + + + 删除 + 编辑 + 添加 + 文件夹路径 + 请选择一个文件夹 + 你确定要删除{0}吗? + + 文件夹 + 在Wox中直接打开收藏的文件夹 + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Folder/Languages/zh-tw.xaml b/Plugins/Wox.Plugin.Folder/Languages/zh-tw.xaml index 27ac719140..c2f6cd8edd 100644 --- a/Plugins/Wox.Plugin.Folder/Languages/zh-tw.xaml +++ b/Plugins/Wox.Plugin.Folder/Languages/zh-tw.xaml @@ -1,12 +1,15 @@ - - - 刪除 - 編輯 - 添加 - 文件夾路徑 - 請選擇一個文件夾 - 你確認要刪除{0}嗎? - + + + 刪除 + 編輯 + 添加 + 文件夾路徑 + 請選擇一個文件夾 + 你確認要刪除{0}嗎? + + 文件夾 + 在Wox中直接打開收藏的文件夾 + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Folder/plugin.json b/Plugins/Wox.Plugin.Folder/plugin.json index d9129e4d34..cd08d56e8c 100644 --- a/Plugins/Wox.Plugin.Folder/plugin.json +++ b/Plugins/Wox.Plugin.Folder/plugin.json @@ -2,7 +2,7 @@ "ID":"B4D3B69656E14D44865C8D818EAE47C4", "ActionKeyword":"*", "Name":"Folder", - "Description":"Provide opening folder from wox directorily. You can add your favorite folders.", + "Description":"Open favorite folder from wox directorily", "Author":"qianlifeng", "Version":"1.0.0", "Language":"csharp", diff --git a/Plugins/Wox.Plugin.Program/Languages/en.xaml b/Plugins/Wox.Plugin.Program/Languages/en.xaml index c0b194f017..84a3e064f4 100644 --- a/Plugins/Wox.Plugin.Program/Languages/en.xaml +++ b/Plugins/Wox.Plugin.Program/Languages/en.xaml @@ -22,5 +22,8 @@ Run As Administrator Open containing folder - + + Program + Search programs in Wox + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Program/Languages/zh-cn.xaml b/Plugins/Wox.Plugin.Program/Languages/zh-cn.xaml index 288e3ba13a..39e5f3b32a 100644 --- a/Plugins/Wox.Plugin.Program/Languages/zh-cn.xaml +++ b/Plugins/Wox.Plugin.Program/Languages/zh-cn.xaml @@ -24,4 +24,7 @@ 以管理员身份运行 打开所属文件夹 + 程序 + 在Wox中搜索程序 + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Program/Languages/zh-tw.xaml b/Plugins/Wox.Plugin.Program/Languages/zh-tw.xaml index 36b4cb42fc..93cf54cb9f 100644 --- a/Plugins/Wox.Plugin.Program/Languages/zh-tw.xaml +++ b/Plugins/Wox.Plugin.Program/Languages/zh-tw.xaml @@ -23,4 +23,7 @@ 以管理員身份運行 打開所屬文件夾 + + 程序 + 在Wox中搜索程序 \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Program/Programs.cs b/Plugins/Wox.Plugin.Program/Programs.cs index 63280d12a2..8ec7599416 100644 --- a/Plugins/Wox.Plugin.Program/Programs.cs +++ b/Plugins/Wox.Plugin.Program/Programs.cs @@ -223,5 +223,14 @@ namespace Wox.Plugin.Program { return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"); } + public string GetTranslatedPluginTitle() + { + return context.API.GetTranslation("wox_plugin_program_plugin_name"); + } + + public string GetTranslatedPluginDescription() + { + return context.API.GetTranslation("wox_plugin_program_plugin_description"); + } } } diff --git a/Plugins/Wox.Plugin.Program/plugin.json b/Plugins/Wox.Plugin.Program/plugin.json index 9185aa7fe8..9f374dded5 100644 --- a/Plugins/Wox.Plugin.Program/plugin.json +++ b/Plugins/Wox.Plugin.Program/plugin.json @@ -2,7 +2,7 @@ "ID":"791FC278BA414111B8D1886DFE447410", "ActionKeyword":"*", "Name":"Program", - "Description":"Provide programs search for Wox.", + "Description":"Search programs in Wox", "Author":"qianlifeng", "Version":"1.0.0", "Language":"csharp", diff --git a/Plugins/Wox.Plugin.Sys/Languages/en.xaml b/Plugins/Wox.Plugin.Sys/Languages/en.xaml index 280d5ff506..a80f951b72 100644 --- a/Plugins/Wox.Plugin.Sys/Languages/en.xaml +++ b/Plugins/Wox.Plugin.Sys/Languages/en.xaml @@ -11,5 +11,8 @@ Close Wox Restart Wox Tweak this app - + + System Commands + Provide System related commands. e.g. shutdown,lock,setting etc. + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Sys/Languages/zh-cn.xaml b/Plugins/Wox.Plugin.Sys/Languages/zh-cn.xaml index 5abec64ce5..ef7d495266 100644 --- a/Plugins/Wox.Plugin.Sys/Languages/zh-cn.xaml +++ b/Plugins/Wox.Plugin.Sys/Languages/zh-cn.xaml @@ -1,15 +1,18 @@ - - - 命令 - 描述 - - 关闭电脑 - 注销 - 锁定这台电脑 - 退出Wox - 重启Wox - 设置 - + + + 命令 + 描述 + + 关闭电脑 + 注销 + 锁定这台电脑 + 退出Wox + 重启Wox + 设置 + + 系统命令 + 系统系统相关的命令。例如,关机,锁定,设置等 + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Sys/Languages/zh-tw.xaml b/Plugins/Wox.Plugin.Sys/Languages/zh-tw.xaml index e393f0d8bd..55abdbf433 100644 --- a/Plugins/Wox.Plugin.Sys/Languages/zh-tw.xaml +++ b/Plugins/Wox.Plugin.Sys/Languages/zh-tw.xaml @@ -1,15 +1,18 @@ - - - 命令 - 描述 - - 關閉電腦 - 註銷 - 鎖定這臺電腦 - 退出Wox - 重啟Wox - 設置 - + + + 命令 + 描述 + + 關閉電腦 + 註銷 + 鎖定這臺電腦 + 退出Wox + 重啟Wox + 設置 + + 系統命令 + 系統系統相關的命令。例如,關機,鎖定,設置等 + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Sys/Sys.cs b/Plugins/Wox.Plugin.Sys/Sys.cs index 80132b29ed..1617772b09 100644 --- a/Plugins/Wox.Plugin.Sys/Sys.cs +++ b/Plugins/Wox.Plugin.Sys/Sys.cs @@ -4,6 +4,7 @@ using System.IO; using System.Reflection; using System.Runtime.InteropServices; using System.Windows.Forms; +using Wox.Infrastructure; namespace Wox.Plugin.Sys { @@ -42,7 +43,7 @@ namespace Wox.Plugin.Sys List results = new List(); foreach (Result availableResult in availableResults) { - if (availableResult.Title.ToLower().StartsWith(query.Search.ToLower())) + if (StringMatcher.IsMatch(availableResult.Title, query.Search) || StringMatcher.IsMatch(availableResult.SubTitle, query.Search)) { results.Add(availableResult); } @@ -142,5 +143,15 @@ namespace Wox.Plugin.Sys return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"); } - } + + public string GetTranslatedPluginTitle() + { + return context.API.GetTranslation("wox_plugin_sys_plugin_name"); + } + + public string GetTranslatedPluginDescription() + { + return context.API.GetTranslation("wox_plugin_sys_plugin_description"); + } + } } diff --git a/Plugins/Wox.Plugin.Url/Images/url.png b/Plugins/Wox.Plugin.Url/Images/url.png index 3b86b637da..90634f7a0a 100644 Binary files a/Plugins/Wox.Plugin.Url/Images/url.png and b/Plugins/Wox.Plugin.Url/Images/url.png differ diff --git a/Plugins/Wox.Plugin.Url/Languages/en.xaml b/Plugins/Wox.Plugin.Url/Languages/en.xaml new file mode 100644 index 0000000000..eec48e692b --- /dev/null +++ b/Plugins/Wox.Plugin.Url/Languages/en.xaml @@ -0,0 +1,11 @@ + + + Open url:{0} + Can't open url:{0} + + URL + Open the typed URL from Wox + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Url/Languages/zh-cn.xaml b/Plugins/Wox.Plugin.Url/Languages/zh-cn.xaml new file mode 100644 index 0000000000..4cab4182cd --- /dev/null +++ b/Plugins/Wox.Plugin.Url/Languages/zh-cn.xaml @@ -0,0 +1,11 @@ + + + 打开链接:{0} + 无法打开链接:{0} + + URL + 从Wox打开链接 + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Url/Languages/zh-tw.xaml b/Plugins/Wox.Plugin.Url/Languages/zh-tw.xaml new file mode 100644 index 0000000000..e4d45de1da --- /dev/null +++ b/Plugins/Wox.Plugin.Url/Languages/zh-tw.xaml @@ -0,0 +1,11 @@ + + + 打開鏈接:{0} + 無法打開鏈接:{0} + + URL + 從Wox打開鏈接 + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Url/UrlPlugin.cs b/Plugins/Wox.Plugin.Url/UrlPlugin.cs index b769a720bb..ae871d2b23 100644 --- a/Plugins/Wox.Plugin.Url/UrlPlugin.cs +++ b/Plugins/Wox.Plugin.Url/UrlPlugin.cs @@ -1,15 +1,17 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; +using System.Reflection; using System.Text.RegularExpressions; using System.Windows; namespace Wox.Plugin.Url { - public class UrlPlugin : IPlugin + public class UrlPlugin : IPlugin, IPluginI18n { //based on https://gist.github.com/dperini/729294 - private const string urlPattern ="^" + + private const string urlPattern = "^" + // protocol identifier "(?:(?:https?|ftp)://|)" + // user:pass authentication @@ -42,6 +44,7 @@ namespace Wox.Plugin.Url "(?:/\\S*)?" + "$"; Regex reg = new Regex(urlPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); + private PluginInitContext context; public List Query(Query query) { @@ -53,7 +56,7 @@ namespace Wox.Plugin.Url new Result { Title = raw, - SubTitle = "Open " + raw, + SubTitle = string.Format(context.API.GetTranslation("wox_plugin_url_open_url"),raw), IcoPath = "Images/url.png", Score = 8, Action = _ => @@ -69,7 +72,7 @@ namespace Wox.Plugin.Url } catch(Exception ex) { - MessageBox.Show(ex.Message, "Could not open " + raw); + context.API.ShowMsg(string.Format(context.API.GetTranslation("wox_plugin_url_canot_open_url"), raw)); return false; } } @@ -98,7 +101,22 @@ namespace Wox.Plugin.Url public void Init(PluginInitContext context) { + this.context = context; + } + public string GetLanguagesFolder() + { + return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"); + } + + public string GetTranslatedPluginTitle() + { + return context.API.GetTranslation("wox_plugin_url_plugin_name"); + } + + public string GetTranslatedPluginDescription() + { + return context.API.GetTranslation("wox_plugin_url_plugin_description"); } } } \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Url/Wox.Plugin.Url.csproj b/Plugins/Wox.Plugin.Url/Wox.Plugin.Url.csproj index a35d32f5e1..aabcb45255 100644 --- a/Plugins/Wox.Plugin.Url/Wox.Plugin.Url.csproj +++ b/Plugins/Wox.Plugin.Url/Wox.Plugin.Url.csproj @@ -64,6 +64,27 @@ PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + + + MSBuild:Compile + Designer + PreserveNewest + + + + + MSBuild:Compile + Designer + PreserveNewest + + - 标题 - 启用 - 图标 - 选择图标 - 取消 - 非法的网页搜索 - 请输入标题 - 请输入触发关键字 - 请输入URL - 触发关键字已经存在,请选择一个新的关键字 - 操作成功 - + + + 删除 + 编辑 + 添加 + 触发关键字 + URL + 启用搜索建议 + 请选择一项 + 你确定要删除 {0} 吗? + + + + 标题 + 启用 + 图标 + 选择图标 + 取消 + 非法的网页搜索 + 请输入标题 + 请输入触发关键字 + 请输入URL + 触发关键字已经存在,请选择一个新的关键字 + 操作成功 + + 网页搜索 + 提供网页搜索能力 + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.WebSearch/Languages/zh-tw.xaml b/Plugins/Wox.Plugin.WebSearch/Languages/zh-tw.xaml index def9146a81..ec1f620ab1 100644 --- a/Plugins/Wox.Plugin.WebSearch/Languages/zh-tw.xaml +++ b/Plugins/Wox.Plugin.WebSearch/Languages/zh-tw.xaml @@ -1,28 +1,31 @@ - - - 刪除 - 編輯 - 添加 - 觸發關鍵字 - URL - 啟用搜索建議 - 請選擇一項 - 你確定要刪除 {0} 嗎? - - - - 標題 - 啟用 - 圖標 - 選擇圖標 - 取消 - 非法的網頁搜索 - 請輸入標題 - 請輸入觸發關鍵字 - 請輸入URL - 觸發關鍵字已經存在,請選擇一個新的關鍵字 - 操作成功 - + + + 刪除 + 編輯 + 添加 + 觸發關鍵字 + URL + 啟用搜索建議 + 請選擇一項 + 你確定要刪除 {0} 嗎? + + + + 標題 + 啟用 + 圖標 + 選擇圖標 + 取消 + 非法的網頁搜索 + 請輸入標題 + 請輸入觸發關鍵字 + 請輸入URL + 觸發關鍵字已經存在,請選擇一個新的關鍵字 + 操作成功 + + 網頁搜索 + 提供網頁搜索能力 + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.WebSearch/WebQueryPlugin.cs b/Plugins/Wox.Plugin.WebSearch/WebQueryPlugin.cs index 10632094af..6399a08f19 100644 --- a/Plugins/Wox.Plugin.WebSearch/WebQueryPlugin.cs +++ b/Plugins/Wox.Plugin.WebSearch/WebQueryPlugin.cs @@ -103,6 +103,16 @@ namespace Wox.Plugin.WebSearch return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"); } + public string GetTranslatedPluginTitle() + { + return context.API.GetTranslation("wox_plugin_websearch_plugin_name"); + } + + public string GetTranslatedPluginDescription() + { + return context.API.GetTranslation("wox_plugin_websearch_plugin_description"); + } + public bool IsInstantQuery(string query) { var strings = query.Split(' '); diff --git a/Plugins/Wox.Plugin.WebSearch/plugin.json b/Plugins/Wox.Plugin.WebSearch/plugin.json index e1bb0fb631..5132ec9e49 100644 --- a/Plugins/Wox.Plugin.WebSearch/plugin.json +++ b/Plugins/Wox.Plugin.WebSearch/plugin.json @@ -2,7 +2,7 @@ "ID":"565B73353DBF4806919830B9202EE3BF", "ActionKeyword":"*", "Name":"Web Searches", - "Description":"Provide the web search ability.", + "Description":"Provide the web search ability", "Author":"qianlifeng", "Version":"1.0.0", "Language":"csharp", diff --git a/Wox.Core/AssemblyHelper.cs b/Wox.Core/AssemblyHelper.cs new file mode 100644 index 0000000000..f9c428178b --- /dev/null +++ b/Wox.Core/AssemblyHelper.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using Wox.Core.Plugin; +using Wox.Infrastructure.Logger; +using Wox.Plugin; + +namespace Wox.Core +{ + internal class AssemblyHelper + { + public static List> LoadPluginInterfaces() where T : class + { + List CSharpPluginMetadatas = PluginManager.AllPlugins.Select(o => o.Metadata).Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList(); + List> plugins = new List>(); + foreach (PluginMetadata metadata in CSharpPluginMetadatas) + { + try + { + Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath)); + List types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(T))).ToList(); + if (types.Count == 0) + { + continue; + } + + foreach (Type type in types) + { + plugins.Add(new KeyValuePair(PluginManager.AllPlugins.First(o => o.Metadata.ID == metadata.ID), + Activator.CreateInstance(type) as T)); + } + } + catch (System.Exception e) + { + Log.Error(string.Format("Couldn't load plugin {0}: {1}", metadata.Name, e.Message)); +#if (DEBUG) + { + throw; + } +#endif + } + } + + return plugins; + } + + public static List LoadInterfacesFromAppDomain() where T : class + { + var interfaceObjects = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(s => s.GetTypes()) + .Where(p => p.IsClass && !p.IsAbstract && p.GetInterfaces().Contains(typeof(T))); + + return interfaceObjects.Select(interfaceObject => (T) Activator.CreateInstance(interfaceObject)).ToList(); + } + } +} diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index 5e93bb0101..ff473061c8 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using System.Threading; using Wox.Core.Exception; +using Wox.Core.i18n; using Wox.Core.UI; using Wox.Core.UserSettings; using Wox.Infrastructure; @@ -23,7 +24,7 @@ namespace Wox.Core.Plugin { public const string ActionKeywordWildcardSign = "*"; private static List pluginMetadatas; - private static List> instantSearches; + private static List> instantSearches; private static List> exclusiveSearchPlugins; public static String DebuggerMode { get; private set; } @@ -99,6 +100,7 @@ namespace Wox.Core.Plugin sw.Stop(); DebugHelper.WriteLine(string.Format("Plugin init:{0} - {1}", pair.Metadata.Name, sw.ElapsedMilliseconds)); pair.InitTime = sw.ElapsedMilliseconds; + InternationalizationManager.Instance.UpdatePluginMetadataTranslations(pair); }); } @@ -178,7 +180,7 @@ namespace Wox.Core.Plugin { //todo:to improve performance, any instant search plugin that takes long than 200ms will not consider a instant plugin anymore return pluginMetadata.Language.ToUpper() == AllowedLanguage.CSharp && - LoadInstantSearches().Any(o => o.Key.ID == pluginMetadata.ID); + LoadInstantSearches().Any(o => o.Key.Metadata.ID == pluginMetadata.ID); } internal static void ExecutePluginQuery(PluginPair pair, Query query) @@ -211,39 +213,11 @@ namespace Wox.Core.Plugin } } - private static List> LoadInstantSearches() + private static List> LoadInstantSearches() { if (instantSearches != null) return instantSearches; - instantSearches = new List>(); - List CSharpPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList(); - - foreach (PluginMetadata metadata in CSharpPluginMetadatas) - { - try - { - Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath)); - List types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IInstantQuery))).ToList(); - if (types.Count == 0) - { - continue; - } - - foreach (Type type in types) - { - instantSearches.Add(new KeyValuePair(metadata, Activator.CreateInstance(type) as IInstantQuery)); - } - } - catch (System.Exception e) - { - Log.Error(string.Format("Couldn't load plugin {0}: {1}", metadata.Name, e.Message)); -#if (DEBUG) - { - throw; - } -#endif - } - } + instantSearches = AssemblyHelper.LoadPluginInterfaces(); return instantSearches; } @@ -261,38 +235,7 @@ namespace Wox.Core.Plugin internal static List> LoadExclusiveSearchPlugins() { if (exclusiveSearchPlugins != null) return exclusiveSearchPlugins; - - exclusiveSearchPlugins = new List>(); - List CSharpPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList(); - - foreach (PluginMetadata metadata in CSharpPluginMetadatas) - { - try - { - Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath)); - List types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IExclusiveQuery))).ToList(); - if (types.Count == 0) - { - continue; - } - - foreach (Type type in types) - { - exclusiveSearchPlugins.Add(new KeyValuePair(AllPlugins.First(o => o.Metadata.ID == metadata.ID), - Activator.CreateInstance(type) as IExclusiveQuery)); - } - } - catch (System.Exception e) - { - Log.Error(string.Format("Couldn't load plugin {0}: {1}", metadata.Name, e.Message)); -#if (DEBUG) - { - throw; - } -#endif - } - } - + exclusiveSearchPlugins = AssemblyHelper.LoadPluginInterfaces(); return exclusiveSearchPlugins; } diff --git a/Wox.Core/UI/ResourceMerger.cs b/Wox.Core/UI/ResourceMerger.cs index 6d7a892982..542200ede2 100644 --- a/Wox.Core/UI/ResourceMerger.cs +++ b/Wox.Core/UI/ResourceMerger.cs @@ -1,7 +1,9 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Windows; using Wox.Core.i18n; +using Wox.Core.Plugin; using Wox.Core.Theme; using Wox.Plugin; @@ -9,38 +11,28 @@ namespace Wox.Core.UI { public class ResourceMerger { - public static void ApplyResources() + internal static void ApplyResources() { Application.Current.Resources.MergedDictionaries.Clear(); ApplyPluginLanguages(); ApplyThemeAndLanguageResources(); } - private static void ApplyThemeAndLanguageResources() + internal static void ApplyThemeAndLanguageResources() { - var UIResourceType = typeof(IUIResource); - var UIResources = AppDomain.CurrentDomain.GetAssemblies() - .SelectMany(s => s.GetTypes()) - .Where(p => p.IsClass && !p.IsAbstract && UIResourceType.IsAssignableFrom(p)); - + var UIResources = AssemblyHelper.LoadInterfacesFromAppDomain(); foreach (var uiResource in UIResources) { - Application.Current.Resources.MergedDictionaries.Add( - ((IUIResource)Activator.CreateInstance(uiResource)).GetResourceDictionary()); + Application.Current.Resources.MergedDictionaries.Add(uiResource.GetResourceDictionary()); } } - public static void ApplyPluginLanguages() + internal 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)); - + var pluginI18ns = AssemblyHelper.LoadInterfacesFromAppDomain(); foreach (var pluginI18n in pluginI18ns) { - string languageFile = InternationalizationManager.Instance.GetLanguageFile( - ((IPluginI18n)Activator.CreateInstance(pluginI18n)).GetLanguagesFolder()); + string languageFile = InternationalizationManager.Instance.GetLanguageFile(pluginI18n.GetLanguagesFolder()); if (!string.IsNullOrEmpty(languageFile)) { Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary @@ -50,5 +42,7 @@ namespace Wox.Core.UI } } } + + } } \ No newline at end of file diff --git a/Wox.Core/Wox.Core.csproj b/Wox.Core/Wox.Core.csproj index 9fc73a2c9a..fa06e3840f 100644 --- a/Wox.Core/Wox.Core.csproj +++ b/Wox.Core/Wox.Core.csproj @@ -69,6 +69,7 @@ + diff --git a/Wox.Core/i18n/Internationalization.cs b/Wox.Core/i18n/Internationalization.cs index d77232091b..25981e89ca 100644 --- a/Wox.Core/i18n/Internationalization.cs +++ b/Wox.Core/i18n/Internationalization.cs @@ -9,6 +9,7 @@ using Wox.Core.Exception; using Wox.Core.UI; using Wox.Core.UserSettings; using Wox.Infrastructure.Logger; +using Wox.Plugin; namespace Wox.Core.i18n { @@ -40,6 +41,7 @@ namespace Wox.Core.i18n { Language language = GetLanguageByLanguageCode(languageCode); ChangeLanguage(language); + UpdateAllPluginMetadataTranslations(); } private Language GetLanguageByLanguageCode(string languageCode) @@ -109,6 +111,36 @@ namespace Wox.Core.i18n return GetLanguagePath(language); } + + internal void UpdateAllPluginMetadataTranslations() + { + List> plugins = AssemblyHelper.LoadPluginInterfaces(); + foreach (var plugin in plugins) + { + UpdatePluginMetadataTranslations(plugin.Key); + } + } + + internal void UpdatePluginMetadataTranslations(PluginPair pluginPair) + { + var pluginI18n = pluginPair.Plugin as IPluginI18n; + if (pluginI18n == null) return; + try + { + pluginPair.Metadata.Name = pluginI18n.GetTranslatedPluginTitle(); + pluginPair.Metadata.Description = pluginI18n.GetTranslatedPluginDescription(); + } + catch (System.Exception e) + { + Log.Warn("Update Plugin metadata translation failed:" + e.Message); +#if (DEBUG) + { + throw; + } +#endif + } + } + private string GetLanguagePath(Language language) { string path = Path.Combine(DefaultLanguageDirectory, language.LanguageCode + ".xaml"); diff --git a/Wox.Plugin/IPluginI18n.cs b/Wox.Plugin/IPluginI18n.cs index cb13dd02bb..c1068ccab8 100644 --- a/Wox.Plugin/IPluginI18n.cs +++ b/Wox.Plugin/IPluginI18n.cs @@ -12,5 +12,9 @@ namespace Wox.Plugin public interface IPluginI18n { string GetLanguagesFolder(); + + string GetTranslatedPluginTitle(); + + string GetTranslatedPluginDescription(); } -} +} \ No newline at end of file diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 482604f4a2..d55e678a3f 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -831,7 +831,7 @@ namespace Wox PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Action = _ => { - TopMostRecordStorage.Instance.Add(result); + TopMostRecordStorage.Instance.AddOrUpdate(result); ShowMsg("Succeed", "", ""); return false; } diff --git a/Wox/Storage/TopMostRecordStorage.cs b/Wox/Storage/TopMostRecordStorage.cs index 87e8feb86b..dc56ed550c 100644 --- a/Wox/Storage/TopMostRecordStorage.cs +++ b/Wox/Storage/TopMostRecordStorage.cs @@ -26,7 +26,8 @@ namespace Wox.Storage { return records.Any(o => o.Value.Title == result.Title && o.Value.SubTitle == result.SubTitle - && o.Value.PluginID == result.PluginID); + && o.Value.PluginID == result.PluginID + && o.Key == result.OriginQuery.RawQuery); } internal void Remove(Plugin.Result result) @@ -38,7 +39,7 @@ namespace Wox.Storage } } - internal void Add(Plugin.Result result) + internal void AddOrUpdate(Plugin.Result result) { if (records.ContainsKey(result.OriginQuery.RawQuery)) {