Skip to content

Commit

Permalink
OCRC: Bump version to 2.0.2
Browse files Browse the repository at this point in the history
1. Fix "Result of OCR is changed after translating" bug
2. Add "Quick Translate" support
  • Loading branch information
pilgrimlyieu committed Sep 5, 2023
1 parent 137e909 commit 2b4b3b5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project/OCRC/OCRC.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @file OCRC.ahk
* @author PilgrimLyieu
* @date 2023/08/24
* @version 2.0.1
* @version 2.0.2
***********************************************************************/
;@Ahk2Exe-SetMainIcon icon\OCRC.ico
Expand Down
9 changes: 5 additions & 4 deletions Project/OCRC/lib/Baidu.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
this.ResultGUI.AddText("x+15 w42 h30", "翻译").SetFont("s16")
this.ResultGUI.AddDropDownList("x+5 w90 vTranslationType AltSubmit Choose" this.config["translation_type"], ["自动检测", "英->中", "中->英", "繁->简", "日->中"]).SetFont("s12")
this.ResultGUI["TranslationType"].OnEvent("Change", ObjBindMethod(this, "__Translate"))
this.ResultGUI["TranslationType"].OnEvent("ContextMenu", ObjBindMethod(this, "__Translate"))
this.ResultGUI.AddText("x+15 w42 h30", "搜索").SetFont("s16")
this.ResultGUI.AddDropDownList("x+5 w105 vSearchEngine AltSubmit Choose" this.config["search_engine"], Baidu_SearchEngines_key).SetFont("s12")
this.ResultGUI["SearchEngine"].OnEvent("Change", ObjBindMethod(this, "__Search"))
Expand Down Expand Up @@ -187,10 +188,10 @@
TranslationGUI.Title := "OCRC (BaiduOCR) 「" translation_engine "" translation_type ")」翻译结果"
TranslationGUI.BackColor := "EBEDF4"
TranslationGUI.SetFont(, "Microsoft YaHei")
TranslationGUI.AddEdit("x20 y20 w600 h300 vResult").SetFont("s18")
TranslationGUI["Result"].Value := Baidu_TranslationEngines[translation_engine].Call(result, Baidu_TranslationTypes[translation_type][1], Baidu_TranslationTypes[translation_type][2], this.config["translation_proxy"])
TranslationGUI["Result"].OnEvent("Change", ObjBindMethod(this, "__Clip"))
this.__Clip(TranslationGUI["Result"])
TranslationGUI.AddEdit("x20 y20 w600 h300 vTranslation").SetFont("s18")
TranslationGUI["Translation"].Value := Baidu_TranslationEngines[translation_engine].Call(result, Baidu_TranslationTypes[translation_type][1], Baidu_TranslationTypes[translation_type][2], {proxy: this.config["translation_proxy"]})
TranslationGUI["Translation"].OnEvent("Change", (CtrlObj, *) => A_Clipboard := CtrlObj.Value)
A_Clipboard := TranslationGUI["Translation"].Value
TranslationGUI.Show("w640 h340")
}

Expand Down
6 changes: 3 additions & 3 deletions Project/OCRC/lib/Common.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ Img2Base(Front := False, Quality := 75) {
return Front ? "data:image/jpg;base64," base64string : base64string
}

GoogleTranslate(text, from := "auto", to := "zh-CN", proxy := "") {
try result := JSON.Parse(Request("https://translate.google.com/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=" from "&tl=" to "&q=" UrlEncode(text), , , , , proxy))["sentences"][1]["trans"]
GoogleTranslate(text, from := "auto", to := "zh-CN", configs := {}) {
try result := JSON.Parse(Request("https://translate.google.com/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=" from "&tl=" to "&q=" UrlEncode(text), , , , , configs.proxy))["sentences"][1]["trans"]
if IsSet(result)
try result := JSON.Parse(Request("https://translate.googleapis.com/translate_a/single?client=gtx&dt=t&sl=" from "&tl=" to "&q=" UrlEncode(text), , , , , proxy))[1][1][1]
try result := JSON.Parse(Request("https://translate.googleapis.com/translate_a/single?client=gtx&dt=t&sl=" from "&tl=" to "&q=" UrlEncode(text), , , , , configs.proxy))[1][1][1]
return IsSet(result) ? result : ""
}

Expand Down

0 comments on commit 2b4b3b5

Please sign in to comment.