Jump to content
zxc3

Prompt me how to see the text in the translation box,https://translate.google.com/

Recommended Posts

zxc3

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

 

03.06.png

Share this post


Link to post
Share on other sites
RTFC

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

Share this post


Link to post
Share on other sites
mikell

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)

 

  • Like 1

Share this post


Link to post
Share on other sites
zxc3
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.

Share this post


Link to post
Share on other sites
AutoBert

@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

Share this post


Link to post
Share on other sites
mikell

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

:)

Share this post


Link to post
Share on other sites
AutoBert

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)

Share this post


Link to post
Share on other sites
VIP

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

Share this post


Link to post
Share on other sites

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.