private void BDTransTextTestBtn_BtnClick(object sender, EventArgs e) { IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "BaiduTranslator", "appID", BDappidTextBox.InputText); IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "BaiduTranslator", "secretKey", BDKeyTextBox.InputText); BaiduTranslator.BaiduTrans_Init(); string ret = BaiduTranslator.Baidu_Translate(BDTestTextBox.InputText, BDDesLangBox.InputText, BDSrcLangBox.InputText); BaiduTransOutInfo oinfo = JsonConvert.DeserializeObject <BaiduTransOutInfo>(ret); if (oinfo.trans_result.Count == 1) { MessageBox.Show(oinfo.trans_result[0].dst, "翻译结果"); } else { MessageBox.Show("翻译过程中出现错误,请先进行API认证测试!", "错误"); } }
private void BaiduAPITestBtn_BtnClick(object sender, EventArgs e) { IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "BaiduTranslator", "appID", BDappidTextBox.InputText); IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "BaiduTranslator", "secretKey", BDKeyTextBox.InputText); BaiduTranslator.BaiduTrans_Init(); string ret = BaiduTranslator.Baidu_Translate("apple", "zh"); BaiduTransOutInfo oinfo = JsonConvert.DeserializeObject <BaiduTransOutInfo>(ret); if (oinfo.error_code == null || oinfo.error_code == "52000") { MessageBox.Show("百度翻译API工作正常!", "提示"); } else { MessageBox.Show("百度翻译API工作异常,错误代码:" + oinfo.error_code + " \n您可以核对官方描述的错误代码来尝试解决问题!", "错误"); } }
private void BDTransTextTestBtn_BtnClick(object sender, EventArgs e) { Common.settings.BDappID = BDappidTextBox.InputText; Common.settings.BDsecretKey = BDKeyTextBox.InputText; BaiduTranslator.BaiduTrans_Init(); string ret = BaiduTranslator.Baidu_Translate(BDTestTextBox.InputText, BDDesLangBox.InputText, BDSrcLangBox.InputText); BaiduTransOutInfo oinfo = JsonConvert.DeserializeObject <BaiduTransOutInfo>(ret); if (oinfo.trans_result.Count == 1) { MessageBox.Show(oinfo.trans_result[0].dst, "翻译结果"); } else { MessageBox.Show("翻译过程中出现错误,请先进行API认证测试!", "错误"); } }
private void BaiduAPITestBtn_BtnClick(object sender, EventArgs e) { Common.settings.BDappID = BDappidTextBox.InputText; Common.settings.BDsecretKey = BDKeyTextBox.InputText; BaiduTranslator.BaiduTrans_Init(); string ret = BaiduTranslator.Baidu_Translate("apple", "zh"); BaiduTransOutInfo oinfo = JsonConvert.DeserializeObject <BaiduTransOutInfo>(ret); if (oinfo.error_code == null || oinfo.error_code == "52000") { MessageBox.Show("百度翻译API工作正常!", "提示"); } else { MessageBox.Show("百度翻译API工作异常,错误代码:" + oinfo.error_code + " \n您可以核对官方描述的错误代码来尝试解决问题!", "错误"); } }
/* * * * const int WM_NCHITTEST = 0x0084; * const int HTLEFT = 10; * const int HTRIGHT = 11; * const int HTTOP = 12; * const int HTTOPLEFT = 13; * const int HTTOPRIGHT = 14; * const int HTBOTTOM = 15; * const int HTBOTTOMLEFT = 0x10; * const int HTBOTTOMRIGHT = 17; * protected override void WndProc(ref Message m) * { * base.WndProc(ref m); * switch (m.Msg) * { * case WM_NCHITTEST: * Point vPoint = new Point((int)m.LParam & 0xFFFF, * (int)m.LParam >> 16 & 0xFFFF); * vPoint = PointToClient(vPoint); * if (vPoint.X <= 5) * if (vPoint.Y <= 5) * m.Result = (IntPtr)HTTOPLEFT; * else if (vPoint.Y >= ClientSize.Height - 5) * m.Result = (IntPtr)HTBOTTOMLEFT; * else m.Result = (IntPtr)HTLEFT; * else if (vPoint.X >= ClientSize.Width - 5) * if (vPoint.Y <= 5) * m.Result = (IntPtr)HTTOPRIGHT; * else if (vPoint.Y >= ClientSize.Height - 5) * m.Result = (IntPtr)HTBOTTOMRIGHT; * else m.Result = (IntPtr)HTRIGHT; * else if (vPoint.Y <= 5) * m.Result = (IntPtr)HTTOP; * else if (vPoint.Y >= ClientSize.Height - 5) * m.Result = (IntPtr)HTBOTTOM; * break; * } * } * * [DllImport("user32.dll")] * public static extern bool ReleaseCapture(); * [DllImport("user32.dll")] * public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); * public const int WM_SYSCOMMAND = 0x0112; * public const int SC_MOVE = 0xF010; * public const int HTCAPTION = 0x0002; */ /* * //之前的窗口改变大小部分代码,已弃用 * private void GameTranslateForm_Move(object sender, EventArgs e) * { * ReleaseCapture(); * * SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); * * } */ /* * //之前的窗口拖动部分代码,已弃用 * private void TransparentPanel_MouseDown(object sender, MouseEventArgs e) * { * mouse_offset = new Point(-e.X, -e.Y); * } * * private void TransparentPanel_MouseMove(object sender, MouseEventArgs e) * { * * if (e.Button == MouseButtons.Left) * { * Point mousePos = Control.MousePosition; * mousePos.Offset(mouse_offset.X, mouse_offset.Y); * Location = mousePos; * } * * } */ /// <summary> /// 自动进行游戏翻译 /// 检查是否设置了分行翻译、去掉一些乱码类型的符号、检查是否空文本 /// </summary> /// <param name="text"></param> /// <param name="srcLang"></param> /// <param name="desLang"></param> public void GameTranslateAuto(string text, string srcLang, string desLang) { //先检查玩家是否设置了分行翻译 bool eachRowTrans = Convert.ToBoolean(IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "Translate_All", "EachRowTrans", "True")); if (eachRowTrans == false) { text = text.Replace("<br>", "").Replace("</br>", "").Replace("\n", "").Replace("\t", "").Replace("\r", ""); } //处理:去掉一些乱码类型的符号 text = text.Replace("_", "").Replace("-", "").Replace("+", ""); string currentAPI; string ret = ""; for (int i = 1; i <= 2; i++) { if (i == 1) { currentAPI = firstTransAPI; } else { currentAPI = secondTransAPI; } if (text == "") { ret = ""; } else { if (currentAPI == "BaiduTranslator") { ret = BaiduTranslator.Baidu_Translate(text, desLang, srcLang); if (ret == "Request Timeout") { ret = "[百度]翻译超时"; } else { BaiduTransOutInfo oinfo = JsonConvert.DeserializeObject <BaiduTransOutInfo>(ret); if (oinfo.trans_result != null) { ret = ""; for (int k = 0; k < oinfo.trans_result.Count; k++) { ret = ret + oinfo.trans_result[k].dst + "\n"; } } else { ret = "[百度]翻译错误"; } } } else if (currentAPI == "TencentTranslator") { ret = TencentTranslator.Fanyijun_Translate(text, desLang, srcLang); if (ret == "Request Timeout") { ret = "[腾讯]翻译超时"; } else { TencentTransOutInfo oinfo = JsonConvert.DeserializeObject <TencentTransOutInfo>(ret); if (oinfo.data != null) { ret = oinfo.data.target_text; } else { ret = "[腾讯]翻译错误"; } } } else if (currentAPI == "JBjTranslator") { ret = JBeijingTranslator.Translate_JapanesetoChinese(text); if (ret == null || ret == "") { ret = ""; } } else if (currentAPI == "TencentOldTranslator") { ret = TencentOldTranslator.TencentOld_Translate(text, desLang, srcLang); if (ret == "Request Timeout") { ret = "[腾讯旧]翻译超时"; } else { TencentOldTransOutInfo oinfo = JsonConvert.DeserializeObject <TencentOldTransOutInfo>(ret); if (oinfo.Response.TargetText != null) { ret = oinfo.Response.TargetText; } else { ret = "[腾讯旧]翻译错误"; } } } else { ret = ""; } } if (i == 1) { firstTransText = ret; } else { secondTransText = ret; } } }