static void Main(string[] args) { TranslateClient client = new TranslateClient("www.emadmokhtar.com"); string tranlsated = client.Translate("أهلا و سهلا", "ar", "en"); Console.WriteLine(tranlsated); //Welcome Console.ReadLine(); }
public void Process(string message) { if (string.IsNullOrWhiteSpace(message)) { Result(""); return; } var translateClient = new TranslateClient("http://lieser-online.de"); var result = translateClient.Translate(message, "DE", "EN"); Result(result); }
public bool OnNewChatMessageFromWorld(OSChatMessage c, out OSChatMessage newc) { string[] operators = c.Message.Split(' '); TranslatorUserInfo UInfo = null; if (operators[0].StartsWith("translate",StringComparison.CurrentCultureIgnoreCase)) { // Example to turn on translator // translator en >> fr translator en > fr // translator fr << en translator fr < en if (operators[2].Contains(">")) //Covers > and >>, { UserInfos[c.SenderUUID] = new TranslatorUserInfo() { enabled = true, From = Aurora.GoogleAPIs.Language.GetValue(operators[1]), To = Aurora.GoogleAPIs.Language.GetValue(operators[3]) }; } else if (operators[2].Contains("<")) //Covers < and <<, { UserInfos[c.SenderUUID] = new TranslatorUserInfo() { enabled = true, From = Aurora.GoogleAPIs.Language.GetValue(operators[3]), To = Aurora.GoogleAPIs.Language.GetValue(operators[1]) }; } } else if (c.Message.StartsWith("translator settings", StringComparison.CurrentCultureIgnoreCase)) { if (UserInfos.TryGetValue(c.SenderUUID, out UInfo)) { if (operators[2] == "enabled") UInfo.enabled = bool.Parse(operators[3]); if (operators[2] == "showold") UInfo.ShowNonTranslated = bool.Parse(operators[3]); } } else if (c.Message.StartsWith("translator help", StringComparison.CurrentCultureIgnoreCase)) { c.Message = "Translate: \n" + "translate from >> to - translates from language 'from' into language 'to'\n" + "Settings:\n" + "translator settings enabled true/false - enables the translator\n" + "translator settings showold true/false - shows the original chat\n" + "Languages\n"; foreach (Aurora.GoogleAPIs.Language lang in Aurora.GoogleAPIs.Language.TranslatableList) { c.Message += lang.Name + " - " + lang.Value + "\n"; } } else if (UserInfos.TryGetValue(c.SenderUUID, out UInfo)) { //If enabled, ask google translator about it if (UInfo.enabled) { TranslateClient tc = new TranslateClient("http://ajax.googleapis.com/ajax/services/language/translate"); string translated = ""; try { translated = tc.Translate(c.Message, UInfo.From.Value, UInfo.To.Value); } catch (Exception ex) { Console.WriteLine("[Aurora Translator]: Error in requesting translation, " + ex.ToString()); } if (!UInfo.ShowNonTranslated) c.Message = translated; else c.Message = translated + " (" + c.Message + ")"; } } newc = c; return true; }