zxc3 Posted June 3, 2016 Posted June 3, 2016 Prompt me how to see the text in the translation box,https://translate.google.com/ Google Chrome, I can not even see the word @translator@. >>>> Visible Text <<<< Chrome Legacy Window
RTFC Posted June 4, 2016 Posted June 4, 2016 (edited) If you're not averse to using IE, here's an example of obtaining google translator output. I just tested that it still works. #include <Array.au3> #include <IE.au3> Local $tag="* # * # *" Local $oIE=_IECreate("https://translate.google.com/#auto/es") Local $oForm=_IEFormGetCollection($oIE,0) Local $oQuery=_IEGetObjByName($oForm,"text") _IEFormElementSetValue($oQuery, $tag & @CR & "Hello World" & @CR & "This is a test" & @CR & $tag) _IEFormSubmit($oForm) _IELoadWait($oIE) Local $oText=_IEGetObjById($oIE,"gt-res-data") $lines=StringSplit(_IEPropertyGet($oText,"innerText"),@CRLF,1) _IEQuit($oIE) _ArrayDelete($lines,_ArraySearch($lines,$tag,1,0,0,1,0) & "-" & $lines[0]) _ArrayDelete($lines,"1-" & _ArraySearch($lines,$tag,1,0,0,1,1)) $lines[0]=UBound($lines)-1 _ArrayDisplay($lines) Edited June 4, 2016 by RTFC snippet added My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O
mikell Posted June 4, 2016 Posted June 4, 2016 You also might try the API $mytext = "Hello world. " & @crlf & "This is a test" $from = "en" $to = "ru" $url = "https://translate.googleapis.com/translate_a/single?client=gtx" $url &= "&sl=" & $from & "&tl=" & $to & "&dt=t&q=" & $mytext $oHTTP = ObjCreate("Microsoft.XMLHTTP") $oHTTP.Open("POST", $url, False) $oHTTP.Send() $sData = $oHTTP.ResponseText Msgbox(0,"raw data", $sData) $sData = StringRegExpReplace($sData, '.*?\["(.*?)"[^\[]*', "$1" & @crlf) Msgbox(0,"output", $sData) AutoBert 1
zxc3 Posted June 4, 2016 Author Posted June 4, 2016 8 hours ago, RTFC said: If you're not averse to using IE, here's an example of obtaining google translator output. I just tested that it still works. #include <Array.au3> #include <IE.au3> Local $tag="* # * # *" Local $oIE=_IECreate("https://translate.google.com/#auto/es") Local $oForm=_IEFormGetCollection($oIE,0) Local $oQuery=_IEGetObjByName($oForm,"text") _IEFormElementSetValue($oQuery, $tag & @CR & "Hello World" & @CR & "This is a test" & @CR & $tag) _IEFormSubmit($oForm) _IELoadWait($oIE) Local $oText=_IEGetObjById($oIE,"gt-res-data") $lines=StringSplit(_IEPropertyGet($oText,"innerText"),@CRLF,1) _IEQuit($oIE) _ArrayDelete($lines,_ArraySearch($lines,$tag,1,0,0,1,0) & "-" & $lines[0]) _ArrayDelete($lines,"1-" & _ArraySearch($lines,$tag,1,0,0,1,1)) $lines[0]=UBound($lines)-1 _ArrayDisplay($lines) Thank you, but I need only a browser Сhrome.
AutoBert Posted June 4, 2016 Posted June 4, 2016 (edited) @mikell: thanks for your API-example. It's a good idea and i hope Google every time is so good: translating your small post: "You can also try the API" translated to german "Sie können auch die API versuchen" and back: "You can also try the API" so i try to make a translate script. Did you know the languages Google supports? (like de=german, en=english, ru=russian) Can you give a link to list of all supprted languages? Or can i use each cc TLD which is similar to List of international vehicle registration codes Edited June 4, 2016 by AutoBert
mikell Posted June 4, 2016 Posted June 4, 2016 AutoBert, #Include <Array.au3> _Codes() Func _Codes() $c = BinaryToString(InetRead("https://translate.google.com", 1)) $c = StringRegExpReplace($c, '(?s).*gt-langs(.*?)</select>.*', "$1") $tmp = StringRegExp($c, 'value=(\w+)>([^<]+)', 3) $res = _ArrayDiv($tmp, 2) _ArraySort($res) _ArrayDisplay($res) EndFunc Func _ArrayDiv($array, $div, $cols = $div) If Mod(UBound($array), $div) <> 0 Then Return SetError(1, 0, 0) If $cols < $div Then Return SetError(2, 0, 0) Local $tmp[UBound($array)/$div][$cols] For $i = 0 to UBound($array)-1 step $div For $j = 0 to $div-1 $tmp[$i/$div][$j] = $array[$i+$j] Next Next Return $tmp EndFunc
AutoBert Posted June 4, 2016 Posted June 4, 2016 Thank's a lot will result a funny script showing tooltips in possivle 102 different languages used google translator to genertate the tooltips for the controls. The translate func was easy, the work was already done by you: Func _Translate($sSource, $from, $to) ;thanks to mikell (autoitscript.com) ;https://www.autoitscript.com/forum/topic/182893-prompt-me-how-to-see-the-text-in-the-translation-boxhttpstranslategooglecom/?do=findComment&comment=1313423 Local $url = "https://translate.googleapis.com/translate_a/single?client=gtx" $url &= "&sl=" & $from & "&tl=" & $to & "&dt=t&q=" & $sSource Local $oHTTP = ObjCreate("Microsoft.XMLHTTP") $oHTTP.Open("POST", $url, False) $oHTTP.Send() Local $sData = $oHTTP.ResponseText $sData = StringRegExpReplace($sData, '.*?\["(.*?)"[^\[]*', "$1" & @CRLF) GUICtrlSetData($idEdtDest, $sData) EndFunc ;==>_Translate but this is the last post from me in this thread, next to this theme in example script (or in own "urgent help me please " thread if running in troubles)
Trong Posted June 4, 2016 Posted June 4, 2016 @AutoBert GUICtrlSetData ? Func _Translate($sSource, $from, $to) ;thanks to mikell (autoitscript.com) ;https://www.autoitscript.com/forum/topic/182893-prompt-me-how-to-see-the-text-in-the-translation-boxhttpstranslategooglecom/?do=findComment&comment=1313423 Local $url = "https://translate.googleapis.com/translate_a/single?client=gtx" $url &= "&sl=" & $from & "&tl=" & $to & "&dt=t&q=" & $sSource Local $oHTTP = ObjCreate("Microsoft.XMLHTTP") $oHTTP.Open("POST", $url, False) $oHTTP.Send() Local $sData = $oHTTP.ResponseText $sData = StringRegExpReplace($sData, '.*?\["(.*?)"[^\[]*', "$1" & @CRLF) Return $sData EndFunc ;==>_Translate Regards,
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now