コード例 #1
0
        Color secondTransTextColor;        //第二翻译源结果颜色

        /// <summary>
        /// UI初始化、翻译API初始化、如果是OCR模式则Hook鼠标点击事件
        /// </summary>
        private void InitUI()
        {
            srcTextLabel           = new Label();
            srcTextLabel.AutoSize  = false;
            srcTextLabel.Text      = "等待源文本";
            srcTextLabel.BackColor = TransparencyColor; //背景色透明
            srcTextLabel.TextAlign = ContentAlignment.TopLeft;

            firstTransTextLabel           = new Label();
            firstTransTextLabel.AutoSize  = false;
            firstTransTextLabel.Text      = "等待源文本";
            firstTransTextLabel.BackColor = TransparencyColor; //背景色透明
            firstTransTextLabel.TextAlign = ContentAlignment.TopLeft;

            secondTransTextLabel           = new Label();
            secondTransTextLabel.AutoSize  = false;
            secondTransTextLabel.Text      = "等待源文本";
            secondTransTextLabel.BackColor = TransparencyColor; //背景色透明
            secondTransTextLabel.TextAlign = ContentAlignment.TopLeft;

            LabelInit();
            this.Controls.Add(srcTextLabel);
            this.Controls.Add(firstTransTextLabel);
            this.Controls.Add(secondTransTextLabel);

            this.FormBorderStyle = FormBorderStyle.None;
            this.SizeChanged    += GameTranslateForm_SizeChanged;
            this.FormClosing    += GameTranslateForm_FormClosing;

            BaiduTranslator.BaiduTrans_Init();
            TencentTranslator.TencentTrans_Init();
            TencentOldTranslator.TencentOldTrans_Init();

            if (Common.TransMode == 2)
            {
                BaiduGeneralOCRBasic.BaiduGeneralOCRBasic_Init();

                //初始化钩子对象
                if (hook == null)
                {
                    hook = new GlobalMouseHook();
                    hook.OnMouseActivity += new MouseEventHandler(Hook_OnMouseActivity);
                }

                IsOCRingFlag = false;
                bool r = hook.Start();
                if (r == false)
                {
                    MessageBox.Show("安装钩子失败!");
                }
            }


            TextFontColorInit();

            firstTransAPI = IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini",
                                                        "Translate_All", "FirstTranslator", "NoTranslate");
            secondTransAPI = IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini",
                                                         "Translate_All", "SecondTranslator", "NoTranslate");
        }
コード例 #2
0
        private void TXOTransTextTestBtn_BtnClick(object sender, EventArgs e)
        {
            IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TencentOldTranslator", "SecretId", TXOappidTextBox.InputText);
            IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TencentOldTranslator", "SecretKey", TXOKeyTextBox.InputText);

            TencentOldTranslator.TencentOldTrans_Init();
            string ret = TencentOldTranslator.TencentOld_Translate(TXOTestTextBox.InputText, TXODesLangBox.InputText, TXOSrcLangBox.InputText);

            TencentOldTransOutInfo oinfo = JsonConvert.DeserializeObject <TencentOldTransOutInfo>(ret);

            if (oinfo.Response.Error == null)
            {
                MessageBox.Show(oinfo.Response.TargetText, "翻译结果");
            }
            else
            {
                MessageBox.Show("翻译过程中出现错误,请先进行API认证测试!", "错误");
            }
        }
コード例 #3
0
        private void TXOAPITestBtn_BtnClick(object sender, EventArgs e)
        {
            IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TencentOldTranslator", "SecretId", TXOappidTextBox.InputText);
            IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TencentOldTranslator", "SecretKey", TXOKeyTextBox.InputText);

            TencentOldTranslator.TencentOldTrans_Init();
            string ret = TencentOldTranslator.TencentOld_Translate("apple", "zh", "en");

            TencentOldTransOutInfo oinfo = JsonConvert.DeserializeObject <TencentOldTransOutInfo>(ret);

            if (oinfo.Response.Error == null)
            {
                MessageBox.Show("腾讯翻译API(旧版)工作正常!", "提示");
            }
            else
            {
                MessageBox.Show("腾讯翻译API(旧版)工作异常,错误代码:" + oinfo.Response.Error.Code + " \n错误信息:" + oinfo.Response.Error.Message, "错误");
            }
        }
コード例 #4
0
        private void TXOTransTextTestBtn_BtnClick(object sender, EventArgs e)
        {
            Common.settings.TXOSecretId  = TXOappidTextBox.InputText;
            Common.settings.TXOSecretKey = TXOKeyTextBox.InputText;

            TencentOldTranslator.TencentOldTrans_Init();
            string ret = TencentOldTranslator.TencentOld_Translate(TXOTestTextBox.InputText, TXODesLangBox.InputText, TXOSrcLangBox.InputText);

            TencentOldTransOutInfo oinfo = JsonConvert.DeserializeObject <TencentOldTransOutInfo>(ret);

            if (oinfo.Response.Error == null)
            {
                MessageBox.Show(oinfo.Response.TargetText, "翻译结果");
            }
            else
            {
                MessageBox.Show("翻译过程中出现错误,请先进行API认证测试!", "错误");
            }
        }
コード例 #5
0
        private void TXOAPITestBtn_BtnClick(object sender, EventArgs e)
        {
            Common.settings.TXOSecretId  = TXOappidTextBox.InputText;
            Common.settings.TXOSecretKey = TXOKeyTextBox.InputText;

            TencentOldTranslator.TencentOldTrans_Init();
            string ret = TencentOldTranslator.TencentOld_Translate("apple", "zh", "en");

            TencentOldTransOutInfo oinfo = JsonConvert.DeserializeObject <TencentOldTransOutInfo>(ret);

            if (oinfo.Response.Error == null)
            {
                MessageBox.Show("腾讯翻译API(旧版)工作正常!", "提示");
            }
            else
            {
                MessageBox.Show("腾讯翻译API(旧版)工作异常,错误代码:" + oinfo.Response.Error.Code + " \n错误信息:" + oinfo.Response.Error.Message, "错误");
            }
        }
コード例 #6
0
        Color secondTransTextColor;     //第二翻译源结果颜色

        /// <summary>
        /// UI初始化、翻译API初始化、如果是OCR模式则Hook鼠标点击事件
        /// </summary>
        private void InitUI()
        {
            srcTextLabel           = new Label();
            srcTextLabel.AutoSize  = false;
            srcTextLabel.Text      = "等待源文本";
            srcTextLabel.BackColor = TransparencyColor; //背景色透明
            srcTextLabel.TextAlign = ContentAlignment.TopLeft;

            firstTransTextLabel           = new Label();
            firstTransTextLabel.AutoSize  = false;
            firstTransTextLabel.Text      = "等待源文本";
            firstTransTextLabel.BackColor = TransparencyColor; //背景色透明
            firstTransTextLabel.TextAlign = ContentAlignment.TopLeft;

            secondTransTextLabel           = new Label();
            secondTransTextLabel.AutoSize  = false;
            secondTransTextLabel.Text      = "等待源文本";
            secondTransTextLabel.BackColor = TransparencyColor; //背景色透明
            secondTransTextLabel.TextAlign = ContentAlignment.TopLeft;

            LabelInit();
            this.Controls.Add(srcTextLabel);
            this.Controls.Add(firstTransTextLabel);
            this.Controls.Add(secondTransTextLabel);

            this.FormBorderStyle = FormBorderStyle.None;
            this.SizeChanged    += GameTranslateForm_SizeChanged;
            this.FormClosing    += GameTranslateForm_FormClosing;

            BaiduTranslator.BaiduTrans_Init();
            TencentTranslator.TencentTrans_Init();
            TencentOldTranslator.TencentOldTrans_Init();

            if (Common.TransMode == 2)
            {
                if (Common.settings.OCRsource == "BaiduOCR")
                {
                    BaiduGeneralOCRBasic.BaiduGeneralOCRBasic_Init();
                }
                else
                {
                    TesseractOCR.TesseractOCR_Init();
                }



                //初始化钩子对象
                if (hook == null)
                {
                    hook = new GlobalMouseHook();
                    hook.OnMouseActivity += new MouseEventHandler(Hook_OnMouseActivity);
                }

                IsOCRingFlag = false;
                bool r = hook.Start();
                if (r == false)
                {
                    MessageBox.Show("安装钩子失败!");
                }
            }


            TextFontColorInit();

            firstTransAPI  = Common.settings.FirstTranslator;
            secondTransAPI = Common.settings.SecondTranslator;
        }