Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
;Winbatch 2007C - quick Google Translation Demo ; ;Stan Littlefield June 27, 2007 ;////////////////////////////////////////////////////////////////// ;No error-handler, use your own GoSub udfs cChoice="Arabic to English BETA,Chinese to English BETA,Chinese (Simplified to Traditional) BETA,Chinese (Traditional to Simplified) BETA," cChoice = cChoice:"English to Arabic BETA,English to Chinese (Simplified) BETA,English to Chinese (Traditional) BETA," cChoice = cChoice:"English to French,English to German,English to Italian,English to Japanese BETA,English to Korean BETA," cChoice = cChoice:"English to Portuguese,English to Russian BETA,English to Spanish,French to English,French to German," cChoice = cChoice:"German to English,German to French,Italian to English,Japanese to English BETA,Korean to English BETA," cChoice = cChoice:"Portuguese to English,Russian to English BETA,Spanish to English" cTrans = "ar|en,zh|en,zh-CN|zh-TW,zh-TW|zh-CN,en|ar,en|zh-CN,en|zh-TW,en|fr,en|de,en|it,en|ja,en|ko,en|pt," cTrans = cTrans:"n|ru,en|es,fr|en,fr|de,de|en,de|fr,it|en,ja|en,ko|en,pt|en,ru|en,es|en" cTrans = StrReplace(cTrans,",",@TAB) cChoice=StrReplace(cChoice,",",@TAB) cChoice1 = ItemExtract(1,cChoice,@TAB) cTxt="translate" cResp="" :start GTFormat=`WWWDLGED,6.1` GTCaption=`Google Translation` GTX=9999 GTY=9999 GTWidth=192 GTHeight=088 GTNumControls=007 GTProcedure=`dlgproc` GTFont=`DEFAULT` GTTextColor=`DEFAULT` GTBackground=`DEFAULT,DEFAULT` GTConfig=0 GT001=`139,047,036,012,PUSHBUTTON,DEFAULT,"Translate",1,1,32,DEFAULT,DEFAULT,DEFAULT` GT002=`139,067,036,012,PUSHBUTTON,DEFAULT,"Quit",2,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT` GT003=`007,007,122,098,DROPLISTBOX,cChoice,%cChoice1%,DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT` GT004=`135,007,050,012,STATICTEXT,DEFAULT,"Select Translation",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT` GT005=`007,025,120,012,EDITBOX,cTxt,DEFAULT,DEFAULT,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT` GT006=`137,025,044,012,STATICTEXT,DEFAULT,"Translate This",DEFAULT,6,DEFAULT,DEFAULT,DEFAULT,DEFAULT` GT007=`009,045,116,036,COMCONTROL,DEFAULT,"mshtml:",DEFAULT,7,DEFAULT,DEFAULT,DEFAULT,DEFAULT` ButtonPushed=Dialog("GT") Exit ;alternate COMCONTROL ;GT007=`009,045,116,036,COMCONTROL,DEFAULT,"Shell.Explorer",DEFAULT,7,DEFAULT,DEFAULT,DEFAULT,DEFAULT` ;//////////////////////////////////////////////////////////////////////////// :udfs #DefineSubRoutine dlgproc(handle,msg,id,p4,p5) Switch msg Case 0 ;Dialog Initialization hwnd=handle DialogProcOptions(handle, 2,1) DialogProcOptions(handle, 5,1) DialogProcOptions(handle,8,1) oIE = DialogObject(handle,007,3) Return(-1) Case 2 Switch id Case 001 cLang = ItemExtract(ItemLocate(cChoice1,cChoice,@TAB),cTrans,@TAB) tlate() Return(-2) Case 002 oIE=0 Return(9) EndSwitch Case 5 cTxt = DialogControlGet(handle,5,3) Return(-2) Case 8 cChoice1 = DialogControlGet(handle,3,6) Return(-2) EndSwitch Return -2 #EndSubRoutine #DefineSubRoutine tlate() cURL="http://www.translate.google.com/translate_t?" cPost="langpair=%cLang%&text=%cTxt%" oHTTP = CreateObject("Msxml2.XMLHTTP") ;oHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") oHTTP.Open("POST", :cURL:cPost, @FALSE) oHTTP.SetRequestHeader("UserAgent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98") oHTTP.Send() cResp = oHTTP.ResponseText oHTTP=0 oIE.Write("") oIE.Close() n= StrIndex(cResp,"id=result_box",0,@FWDSCAN) If n>0 cResp=StrSub(cResp,n+22,-1) cResp=StrSub(cResp,1,StrIndex(cResp,"</div",0,@FWDSCAN)-1) cResp1="<HTML><BODY>":@CRLF:cResp:@CRLF:"</BODY></HTML>" oIE.Writeln(cResp) Else oIE.Writeln("<HTML><BODY>":@CRLF:"Translation Failed":@CRLF:"</BODY></HTML>") EndIf #EndSubRoutine Return
Article ID: W17467
File Created: 2019:02:25:08:29:52
Last Updated: 2019:02:25:08:29:52