public void ToTranslate(string cbText) { switch (cbText) { case "百度翻译": { Baidu baidu = new Baidu(sourceLanguage, targetLanguage, folderPath, label6); baidu.TranslateThread(); break; } case "搜狗翻译": { SouGou sg = new SouGou(sourceLanguage, targetLanguage, folderPath, label6); sg.TranslateThread(); break; } default: { MessageBox.Show("不支持的翻译!", "Translation Software"); break; } } }
// 翻译 private string Translate(bool sendToWindow) { string from = "auto", dst = ""; try { if (textBox1_Source.Text == "") { return(""); } if (comboBox2_DestLang.SelectedItem.ToString() != "不翻译") { if (tranInterface.IndexOf("百度") != -1) { Baidu.Translation(textBox1_Source.Text, from, Baidu_to[comboBox2_DestLang.SelectedIndex], out string src, out dst); } else if (tranInterface.IndexOf("有道") != -1) { dst = Youdao.Translation(textBox1_Source.Text, from, Youdao_to[comboBox2_DestLang.SelectedIndex]); } else if (tranInterface.IndexOf("腾讯") != -1) { dst = Tengxun.Translation(textBox1_Source.Text, from, Tengxun_to[comboBox2_DestLang.SelectedIndex]); } } else { dst = textBox1_Source.Text; } // 保存当前选项 FrmMain.TranDestLang = comboBox2_DestLang.SelectedIndex; FrmMain.AutoPressKey = comboBox1_SourceLang.SelectedIndex; FrmMain.AutoSend = checkBox1_AutoSend.Checked; if (!sendToWindow) // 不将译文发送到窗口 { return(dst); } else { this.WindowState = FormWindowState.Minimized; SendText(dst); } } catch (Exception ex) { MessageBox.Show(ex.Message, "翻译", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (sendToWindow) // 如果是不将译文发送到窗口,则不会关闭本窗口 { this.Close(); } } return(dst); }
public void BaiduTest() { Channel channle = new Baidu(videoPath, coverPath, new string[] { "123", "321" }, title, introduction, null, null); channle.Operate(); Console.ReadLine(); }
private void BaiduTranslation() { chkBaidu.Checked = false; chkBaidu.Enabled = false; textBaidu.Text = Baidu.Translation(textOriginal.Text, langDic["百度"][cobForm.Text], langDic["百度"][cobTo.Text]); chkBaidu.Enabled = true; chkBaidu.Checked = true; }
void onInterstitialEvent(string eventName, string msg) { Debug.Log("handler onBaiduEvent---" + eventName + " " + msg); if (eventName == BaiduEvent.onAdLoaded) { Baidu.Instance().showInterstitial(); } }
// 百度翻译key private void button_BaiduTranKeyTest_Click(object sender, EventArgs e) { try { Baidu.Translate("翻译测试", "中文", "英语", textBox_BaiduTranId.Text, textBox_BaiduTranPw.Text); MessageBox.Show("测试成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "失败", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
// 百度文本纠错Key private void button_BaiduCorrectionKeyTest_Click(object sender, EventArgs e) { try { Baidu.GetAccessToken(textBox_BaiduCorrectionAk.Text, textBox_BaiduCorrectionSk.Text); MessageBox.Show("测试成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "失败", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
void OnGUI() { if (GUI.Button(new Rect(0, 0, 100, 60), "initbaidu")) { Baidu ad = Baidu.Instance(); #if UNITY_IOS ad.initBaidu("app id", "banner id", "institial id", "video id"); #else ad.initBaidu("app id", "banner id", "institial id", "video id"); #endif } if (GUI.Button(new Rect(0, 100, 100, 60), "showInstitial")) { Baidu ad = Baidu.Instance(); if (ad.isInterstitialReady()) { ad.showInterstitial(); } else { ad.loadInterstitial(); } } if (GUI.Button(new Rect(0, 200, 100, 60), "showVideo")) { Baidu ad = Baidu.Instance(); if (ad.isVideoReady()) { ad.showVideo(); } else { ad.loadVideo(); } } if (GUI.Button(new Rect(240, 100, 100, 60), "showbanner")) { Baidu.Instance().showBannerRelative(AdSize.Banner320x50, AdPosition.BOTTOM_CENTER, 0); } if (GUI.Button(new Rect(240, 200, 100, 60), "showbannerABS")) { Baidu.Instance().showBannerAbsolute(AdSize.Banner728x90, 0, 30); } if (GUI.Button(new Rect(240, 300, 100, 60), "hidebanner")) { Baidu.Instance().removeBanner(); } }
public static string Translator(string text, string from, string to) { if (TranslatorUserMethod == 1) { text = Google.Translate(text, from, to); } else if (TranslatorUserMethod == 2) { text = BingTranslator.Translate(text, from, to.ToLower()); } else if (TranslatorUserMethod == 3) { text = Baidu.Translate(text, from, to); } return(text); }
public Geocoding GetCurrentMapType() { Geocoding geo; if (Utils.GetCache <LoginUserInfo>(cacheKey).MapType == MapType.BAIDU) { geo = new Baidu(); geo.key = Utils.GetBaiDuKey(); } else { geo = new Amap(); geo.key = Utils.GetAmapKey(); } return(geo); }
//private DialogResult ShowScreenShotDialog(out Image img) //{ // if (shot != null && !shot.IsDisposed) // shot.Dispose(); // shot = new FrmScreenShot(); // if (shot.Start() == DialogResult.Cancel) // 显示截图窗口 // { // img = null; // return DialogResult.Cancel; // } // else // { // img = (Image)shot.CaptureImage?.Clone(); // return DialogResult.OK; // } //} // 调用翻译Api翻译后显示翻译结果 private async void TranslateAndShowResult(Image captureImage) { string src = "", dst = ""; await Task.Run(() => { try { if (tranInterface.IndexOf("百度") != -1) { Baidu.PictureTranslation(captureImage, "auto", Baidu.LangDict[destLang], out src, out dst); } else if (tranInterface.IndexOf("有道") != -1) { Youdao.PictureTranslation(captureImage, "auto", Youdao.LangDict[destLang], out src, out dst); } else if (tranInterface.IndexOf("腾讯") != -1) { Tengxun.PictureTranslation(captureImage, "auto", Tengxun.LangDict[destLang], out src, out dst); } } catch (Exception ex) { dst = ("错误:" + ex.Message); } }); if (copySourceTextToClip) { Clipboard.SetText(src);// 复制原文到剪切板 } if (copyDestTextToClip) { Clipboard.SetText(dst);// 复制译文到剪切板 } if (isSpeak) { Speech(dst); // 文字转语音 } this.Invoke(new Action(() => ShowText(dst))); // 显示到桌面 }
private void button_BaiduKeyTest_Click(object sender, EventArgs e) { if (TextBoxIsEmpty(groupBox1))// 先判断是否有 没有填的项 { return; } TextBoxRemoveSpace(groupBox1); // 移除空格 SaveBaiduKeyToDict(); if (!Baidu.BaiduKeyTest()) // 百度翻译 { return; } try { ConfigFile.WriteFile(config); MessageBox.Show("测试成功!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("保存到文件失败!\n" + ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button_BaiduKeyTest_Click(object sender, EventArgs e) { if (TextBoxIsEmpty(groupBox1))// 先判断是否有 没有填的项 { return; } // 先保存数据 // 百度翻译 InitDictionary(changeBaiduKey: true); if (!Baidu.BaiduKeyTest()) { return; } try { ConfigFile.WriteFile(config); MessageBox.Show("测试成功!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("保存到文件失败!\n" + ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
// 翻译 private string Translate(bool sendToWindow) { try { if (textBox1_Source.Text == "") { return(""); } if (comboBox2_DestLang.SelectedItem.ToString() != "不翻译") { if (sourceOfTran.IndexOf("有道") != -1) { from = "zh-CHS"; Youdao.YoudaoTran(textBox1_Source.Text, from, Youdao_to[comboBox2_DestLang.SelectedIndex], out src, out dst); } else { from = "zh"; Baidu.Translate(textBox1_Source.Text, from, Baidu_to[comboBox2_DestLang.SelectedIndex], out src, out dst); } } else { dst = textBox1_Source.Text; } // 保存当前选项 FrmMain.TranDestLang = comboBox2_DestLang.SelectedIndex; FrmMain.AutoPressKey = comboBox1_SourceLang.SelectedIndex; FrmMain.AutoSend = checkBox1_AutoSend.Checked; if (!sendToWindow) // 不将译文发送到窗口 { return(dst); } this.WindowState = FormWindowState.Minimized; // 查找窗口句柄 IntPtr hwnd = FindWindowHandle(); // 激活窗口 if (!Api.SetForegroundWindow(hwnd)) { throw new Exception("无法激活窗口!"); } Thread.Sleep(500); KeyBoard(Key[comboBox1_SourceLang.SelectedIndex]); Thread.Sleep(500); SendKeys.SendWait(dst); // SendKeys.Send(dst); // 输入要发送的内容 Thread.Sleep(1000); if (checkBox1_AutoSend.Checked) // 自动发送(按下回车键) { KeyBoard(Keys.Enter); } } catch (Exception ex) { MessageBox.Show(ex.Message, "翻译", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (sendToWindow) // 如果是不将译文发送到窗口,则不会关闭本窗口 { this.Close(); } } return(dst); }
// Use this for initialization void Start() { Baidu.Instance().bannerEventHandler += onBannerEvent; Baidu.Instance().interstitialEventHandler += onInterstitialEvent; // Baidu.Instance().videoEventHandler += onVideoEvent; }
// 截图翻译 private void ScreenTran() { string from = "en", src, dst = null; Image captureImage = default; FrmScreenShot shot = new FrmScreenShot(); SetStateDelegate setState = new SetStateDelegate(MinimizeWindow); try { // 截图翻译并显示 if (tranMode == TranMode.TranAndShowText) { this.Invoke((EventHandler) delegate { setState(true); }); Thread.Sleep(200); // 如果是固定区域翻译(isFixedScreen = true则视为固定区域翻译) if (isFixedScreen == true) { captureImage = FixedScreen(); } else { shot.CopyScreen(); if (shot.ShowDialog() == DialogResult.Cancel) // 显示截图窗口 { return; } captureImage = shot.CaptureImage; } // 翻译模式isEnToZh=true为英译中,false为俄译中 if (isEnToZh == false) { from = "ru"; } // sourceOfTran有“有道”两字使用有道翻译,否则使用百度翻译 if (sourceOfTran.IndexOf("有道") != -1) { Youdao.YoudaoTran(null, from, "zh-CHS", out src, out dst, captureImage); } else { Baidu.BaiduTran(captureImage, from, out src, out dst); } if (copySourceTextToClip) { Clipboard.SetText(src);// 复制原文到剪切板 } if (copyDestTextToClip) { Clipboard.SetText(dst);// 复制译文到剪切板 } if (isSpeak) { SpeechSynthesizer speech = new SpeechSynthesizer(); speech.Rate = 3; // 语速 speech.SpeakAsync(dst); } } else { dst = showCont; } // 不为空 if (!string.IsNullOrEmpty(dst)) { ShowText(dst); } } catch (Exception ex) { if (ex.GetType().FullName == "System.Threading.ThreadAbortException") { return; } // 显示错误 ShowText("错误:" + ex.Message); } finally { if (shot != null && !shot.IsDisposed) { shot.Dispose(); } //if (captureImage != null) // captureImage.Dispose(); } }
public void updateSite() { currentStep = 0; this.pr = int.Parse(Google.GetPageRank(url)); sendP(); this.googleIndex = int.Parse(trim(Google.Index(url))); sendP(); this.googleLink = int.Parse(trim(Google.Link(url))); sendP(); this.baiduIndex = int.Parse(trim(Baidu.Index(url))); sendP(); this.baiduLink = int.Parse(trim(Baidu.Link(url))); sendP(); this.sogouRank = int.Parse(Sogou.Rank(url)); sendP(); this.sogouIndex = int.Parse(trim(Sogou.Index(url))); sendP(); this.sosoIndex = int.Parse(trim(Soso.Index(url))); sendP(); this.yahooIndex = int.Parse(trim(Yahoo.Index(url))); sendP(); Dictionary <String, String> data = Utils.Alexa.getAlexa(url); sendP(); String temp = null; if (data.TryGetValue("addr", out temp)) { alexa.Addr = temp; } if (data.TryGetValue("owner", out temp)) { alexa.Owner = temp; } if (data.TryGetValue("email", out temp)) { alexa.Email = temp; } if (data.TryGetValue("linksin", out temp)) { alexa.Linksin = uint.Parse(temp); } if (data.TryGetValue("addr", out temp)) { alexa.Addr = temp; } if (data.TryGetValue("title", out temp)) { alexa.Title = temp; } if (data.TryGetValue("desc", out temp)) { alexa.Desc = temp; } if (data.TryGetValue("rank", out temp)) { alexa.Rank = uint.Parse(temp); } if (data.TryGetValue("reach", out temp)) { alexa.Reach = uint.Parse(temp); } if (data.TryGetValue("delta", out temp)) { alexa.Delta = int.Parse(temp); } if (data.TryGetValue("country", out temp)) { alexa.Country = temp; } if (data.TryGetValue("countryRank", out temp)) { alexa.CountryRank = uint.Parse(temp); } sendP(); }