Jump to content

Recommended Posts

Posted (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 by RTFC
snippet added
Posted

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)

 

Posted
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.

Posted (edited)

@mikell: thanks for your API-example. It's a good idea and i hope Google every time is so good:

  1. translating your small post: "You can also try the API"
  2. translated to german "Sie können auch die API versuchen"
  3. 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)

Edited by AutoBert
Posted

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

:)

Posted

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 :D " thread if running in troubles)

Posted

@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,
 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...