Created
November 10, 2015 22:26
-
-
Save lances101/654a8792b017b018c97c to your computer and use it in GitHub Desktop.
Wox Translation Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Decompiled with JetBrains decompiler | |
// Type: TranslateWox.Main | |
// Assembly: TranslateWox, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | |
// MVID: 0A51035E-8791-4FC6-8557-D3506E321CD1 | |
// Assembly location: C:\Users\Boris\Documents\WoxTranslation\TranslateWox.dll | |
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Net; | |
using System.Text; | |
using Wox.Plugin; | |
namespace TranslateWox | |
{ | |
public class Main : IPlugin | |
{ | |
public string[,] Languages = new string[64, 2] | |
{ | |
{ | |
"Afrikaans", | |
"af" | |
}, | |
{ | |
"Albanian", | |
"sq" | |
}, | |
{ | |
"Arabic", | |
"ar" | |
}, | |
{ | |
"Azerbaijani", | |
"az" | |
}, | |
{ | |
"Basque", | |
"eu" | |
}, | |
{ | |
"Korean", | |
"ko" | |
}, | |
{ | |
"Belarusian", | |
"be" | |
}, | |
{ | |
"Bulgarian", | |
"bg" | |
}, | |
{ | |
"Catalan", | |
"ca" | |
}, | |
{ | |
"Chinese Simplified", | |
"zh-CN" | |
}, | |
{ | |
"Chinese Traditional", | |
"zh-TW" | |
}, | |
{ | |
"Croatian", | |
"hr" | |
}, | |
{ | |
"Czech", | |
"cs" | |
}, | |
{ | |
"Danish", | |
"da" | |
}, | |
{ | |
"Dutch", | |
"nl" | |
}, | |
{ | |
"English", | |
"en" | |
}, | |
{ | |
"Esperanto", | |
"eo" | |
}, | |
{ | |
"Estonian", | |
"et" | |
}, | |
{ | |
"Filipino", | |
"tl" | |
}, | |
{ | |
"Finnish", | |
"fi" | |
}, | |
{ | |
"French", | |
"fr" | |
}, | |
{ | |
"Galician", | |
"gl" | |
}, | |
{ | |
"Georgian", | |
"ka" | |
}, | |
{ | |
"German", | |
"de" | |
}, | |
{ | |
"Greek", | |
"el" | |
}, | |
{ | |
"Gujarati", | |
"gu" | |
}, | |
{ | |
"Haitian Creole", | |
"ht" | |
}, | |
{ | |
"Hebrew", | |
"iw" | |
}, | |
{ | |
"Hindi", | |
"hi" | |
}, | |
{ | |
"Hungarian", | |
"hu" | |
}, | |
{ | |
"Icelandic", | |
"is" | |
}, | |
{ | |
"Indonesian", | |
"id" | |
}, | |
{ | |
"Irish", | |
"ga" | |
}, | |
{ | |
"Italian", | |
"it" | |
}, | |
{ | |
"Japanese", | |
"ja" | |
}, | |
{ | |
"Kannada", | |
"kn" | |
}, | |
{ | |
"Bengali", | |
"bn" | |
}, | |
{ | |
"Latin", | |
"la" | |
}, | |
{ | |
"Latvian", | |
"lv" | |
}, | |
{ | |
"Lithuanian", | |
"lt" | |
}, | |
{ | |
"Macedonian", | |
"mk" | |
}, | |
{ | |
"Malay", | |
"ms" | |
}, | |
{ | |
"Maltese", | |
"mt" | |
}, | |
{ | |
"Norwegian", | |
"no" | |
}, | |
{ | |
"Persian", | |
"fa" | |
}, | |
{ | |
"Polish", | |
"pl" | |
}, | |
{ | |
"Portuguese", | |
"pt" | |
}, | |
{ | |
"Romanian", | |
"ro" | |
}, | |
{ | |
"Russian", | |
"ru" | |
}, | |
{ | |
"Serbian", | |
"sr" | |
}, | |
{ | |
"Slovak", | |
"sk" | |
}, | |
{ | |
"Slovenian", | |
"sl" | |
}, | |
{ | |
"Spanish", | |
"es" | |
}, | |
{ | |
"Swahili", | |
"sw" | |
}, | |
{ | |
"Swedish", | |
"sv" | |
}, | |
{ | |
"Tamil", | |
"ta" | |
}, | |
{ | |
"Telugu", | |
"te" | |
}, | |
{ | |
"Thai", | |
"th" | |
}, | |
{ | |
"Turkish", | |
"tr" | |
}, | |
{ | |
"Ukrainian", | |
"uk" | |
}, | |
{ | |
"Urdu", | |
"ur" | |
}, | |
{ | |
"Vietnamese", | |
"vi" | |
}, | |
{ | |
"Welsh", | |
"cy" | |
}, | |
{ | |
"Yiddish", | |
"yi" | |
} | |
}; | |
private PluginInitContext _context; | |
public void Init(PluginInitContext context) | |
{ | |
this._context = context; | |
} | |
public List<Result> Query(Query query) | |
{ | |
List<Result> list = new List<Result>(); | |
List<string> actionParameters = query.ActionParameters; | |
if (actionParameters.Count == 1 || actionParameters.Count == 0) | |
{ | |
for (int index = 0; index < this.Languages.GetLength(0); ++index) | |
{ | |
string str = this.Languages[index, 0]; | |
string countrycode = this.Languages[index, 1]; | |
list.Add(new Result() | |
{ | |
Title = str, | |
SubTitle = countrycode, | |
IcoPath = "Images\\pic.png", | |
Action = (Func<ActionContext, bool>)(e => | |
{ | |
this._context.API.ChangeQuery(query.RawQuery + countrycode + " ", false); | |
return false; | |
}) | |
}); | |
} | |
} | |
else if (actionParameters.Count > 1) | |
{ | |
string input = actionParameters[2]; | |
string from = actionParameters[0]; | |
string to = actionParameters[1]; | |
for (int index = 3; index < actionParameters.Count; ++index) | |
input = input + " " + actionParameters[index]; | |
string str = this.TranslateText(input, from, to); | |
list.Add(new Result() | |
{ | |
Title = str, | |
SubTitle = "from " + from + " to " + to + " : " + input, | |
IcoPath = "Images\\pic.png", | |
Action = (Func<ActionContext, bool>)(e => | |
{ | |
Process.Start("http://www.google.com/translate_t?hl=en&ie=UTF8&text=" + input + "&langpair=" + from + "|" + to); | |
return false; | |
}) | |
}); | |
} | |
return list; | |
} | |
public string TranslateText(string input, string from, string to) | |
{ | |
string str1 = new WebClient() | |
{ | |
Encoding = Encoding.UTF8 | |
}.DownloadString(string.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1}|{2}", (object)input, (object)from, (object)to)); | |
string str2 = str1.Substring(str1.IndexOf("<span title=\"") + "<span title=\"".Length); | |
string str3 = str2.Substring(str2.IndexOf(">") + 1); | |
return str3.Substring(0, str3.IndexOf("</span>")).Trim(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment