Jump to content

google translator


eltorro
 Share

Recommended Posts

AZJIO,

The Encoding.au3 is missing from the source files. But overall a good example/application.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 6 months later...

updat : :support any language "arabic :shifty:right characters " and read a long string

Opt("GUIONEVENTMODE", 1)
Global $link = "http://translate.google.com/"
Global $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
Global $TITEL = "Google Translate"

Global $SCRIPTGUI = GUICreate($TITEL, 841, 448, -1, -1, -2133983232)
GUISetOnEvent(-3, "__EXIT")
Global $EDIT1 = GUICtrlCreateEdit("", 0, 0, 841, 156)
GUICtrlSetResizing(-1, 774)
Global $Edit2 = GUICtrlCreateEdit("", 0, 160, 841, 260)
GUICtrlSetFont(-1, 15, 400, 0, "Arial")
GUICtrlSetResizing(-1, 870)
Global $Label1 = GUICtrlCreateLabel("Detec lang : ", 23, 425, 180, 17)
GUICtrlSetResizing(-1, 834)
GUICtrlCreateLabel("translate to ", 155, 425, 59, 17)
GUICtrlSetResizing(-1, 834)
Global $COMBO1 = GUICtrlCreateCombo("", 215, 423, 127, 25, 2097155)
GUICtrlSetOnEvent($COMBO1, "__GOTRAN")
GUICtrlSetData($COMBO1, __lGUI())
GUICtrlSetResizing(-1, 834)
Global $BUTTON1 = GUICtrlCreateButton("Speak", 352, 421, 75, 25)
GUICtrlSetOnEvent($BUTTON1, "__GOSPEAK")
GUICtrlSetResizing(-1, 834)
GUISetState()

While True
    Sleep(1000)
WEnd

Func __GOSPEAK()
    Local $readtxt
    $readtxt = GUICtrlRead($Edit2)
    If $readtxt = "" Then Return
    WinSetTitle($SCRIPTGUI, "", "WAIT DOWNLOAD DATA...")
    __GOOGLESPEEK($readtxt)
    WinSetTitle($SCRIPTGUI, "", $TITEL)
EndFunc   ;==>__GOSPEAK
Func __GOTRAN()
    Local $readtxt = GUICtrlRead($EDIT1)
    If $readtxt = "" Then Return
    WinSetTitle($SCRIPTGUI, "", "WAIT DOWNLOAD DATA...")
    __GOOGLETRANS($readtxt)
    WinSetTitle($SCRIPTGUI, "", $TITEL)
EndFunc   ;==>__GOTRAN
Func __GOOGLETRANS($TEXTTOTRANS)
    Local $TXT, $STEXT1, $STEXT, $STEXT2, $STEXT3, $STEXT4, $STEXT5, $Autodetlang
    
    $Autodetlang = __DETLANG(StringLeft(StringRegExpReplace($TEXTTOTRANS, "\r\n|\r|\n", Chr(32)), 33))

    $Autodetlang = __SLANG($Autodetlang)
    
    GUICtrlSetData($Label1, "Detec lang : " & $Autodetlang)
    
    $Gettrnlang = __SLANG(GUICtrlRead($COMBO1), 1)
    
    If StringInStr("ar fa iw ur yi", $Gettrnlang) > 0 Then
        GUICtrlSetStyle($Edit2, 3152064 + 2)
    Else
        GUICtrlSetStyle($Edit2, 3152064 + 0)
    EndIf
    
    GUICtrlSetData($Edit2, "")
    $STEXT = StringSplit($TEXTTOTRANS, @CRLF, 1)
    For $i = 1 To $STEXT[0]
        $STEXT1 = StringSplit($STEXT[$i], Chr(32), 1)
        For $O = 1 To $STEXT1[0]
            $TXT &= $STEXT1[$O] & Chr(32)
            If StringLen($TXT) > 90 Or $O = $STEXT1[0] Then
                $STEXT2 = StringSplit($TXT, ".")
                For $z = 1 To $STEXT2[0]
                    $STEXT3 = StringSplit($STEXT2[$z], '"')
                    For $L = 1 To $STEXT3[0]
                        $STEXT4 = StringSplit($STEXT3[$L], '?')
                        For $M = 1 To $STEXT4[0]
                            $STEXT5 = StringSplit($STEXT4[$M], '!')
                            For $S = 1 To $STEXT5[0]
                                if StringIsSpace($STEXT5[$S]) Then ContinueLoop
                                _Guisetdata(__TRANTXT($STEXT5[$S], $Gettrnlang))
                                $TXT = ""
                                If $S <> $STEXT5[0] Then _Guisetdata('!')
                            Next
                            If $M <> $STEXT4[0] Then _Guisetdata('?')
                        Next
                        If $L <> $STEXT3[0] Then _Guisetdata('"')
                    Next
                    If $z <> $STEXT2[0] Then _Guisetdata(".")
                Next
            EndIf
        Next
        If $i <> $STEXT[0] Then _Guisetdata(@CRLF)
    Next
EndFunc   ;==>__GOOGLETRANS
Func __SLANG($LANGG, $OOPT = 2)
    Local $OPT = 2
    Local $SLIS = StringSplit(__LISLll(), ";")
    For $i = 1 To $SLIS[0]
        Local $GETl = StringSplit($SLIS[$i], "|")
        If StringInStr($GETl[$OOPT], $LANGG, 2) Then
            If $OOPT = 2 Then $OPT = 1
            Return $GETl[$OPT]
        EndIf
    Next
EndFunc   ;==>__SLANG
Func __TRANTXT($TXT, $tto)
    Local $ENCODESSTRING, $READ, $DATA
    $ENCODESSTRING = __URIENCODE($TXT)
    $READ = __DOWN($link & "translate_a/t?client=t&sl=auto&text=" & $ENCODESSTRING & "&tl=" & $tto)
    $DATA = StringSplit($READ, '"')
    Return $DATA[2]
EndFunc   ;==>__TRANTXT
Func REV($TXT)
    Local $split, $LOL
    $split = StringSplit($TXT, " ", 1)
    For $i = $split[0] To 1 Step -1
        $LOL &= $split[$i] & " "
    Next
    Return $LOL
EndFunc   ;==>REV
Func _Guisetdata($text)
    GUICtrlSetData($Edit2, GUICtrlRead($Edit2) & $text & " ")
EndFunc   ;==>_Guisetdata
Func __GOOGLESPEEK($TEXTTOSPEEK)
    Local $TXT, $OPEN, $STEXT1, $READ = "", $ENCODESSTRING, $RESTRING, $LANG, _
            $MPFIL = FileGetShortName(@ScriptDir) & "\" & GUICtrlRead($COMBO1) & "__" & Random(1, 99, 1) & ".MP3"
    
    $RESTRING = StringRegExpReplace($TEXTTOSPEEK, "\r\n|\r|\n", " ")
    
    $LANG = __DETLANG(StringLeft($RESTRING, 33))
    
    $OPEN = FileOpen($MPFIL, 18)
    $STEXT1 = StringSplit($RESTRING, " ", 1)
    For $O = 1 To $STEXT1[0]
        $TXT &= $STEXT1[$O] & " "
        If StringLen($TXT) > 90 Or $O = $STEXT1[0] Then
            $ENCODESSTRING = __URIENCODE($TXT)
            FileWrite($OPEN, InetRead($link & "translate_tts?ie=UTF-8&tl=" & $LANG & "&q=" & $ENCODESSTRING, 1))
            $TXT = ""
        EndIf
    Next
    FileClose($OPEN)
    
    SoundPlay($MPFIL)
EndFunc   ;==>__GOOGLESPEEK
Func __DETLANG($STRI)
    Local $TST, $LANGGG
    $STRI = __URIENCODE($STRI)
    $TST = __DOWN($link & "translate_a/t?client=t&sl=auto&text=" & $STRI)
    $LANGGG = StringLeft(StringTrimLeft($TST, StringInStr($TST, '[["', 0, -1) + 2), 2)
    Return $LANGGG
EndFunc   ;==>__DETLANG
Func __DOWN($URL)
    $oHTTP.Open("GET", $URL, False)
    $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1")
    $oHTTP.Send("")
    $oReceived = $oHTTP.ResponseText
    Return $oReceived
EndFunc   ;==>__DOWN
Func __URIENCODE($SDATA)
    Local $ADATA = StringSplit(BinaryToString(StringToBinary($SDATA, 4), 1), "")
    Local $NCHAR
    $SDATA = ""
    For $i = 1 To $ADATA[0]
        $NCHAR = Asc($ADATA[$i])
        Switch $NCHAR
            Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126
                $SDATA &= $ADATA[$i]
            Case 32
                $SDATA &= "+"
            Case Else
                $SDATA &= "%" & Hex($NCHAR, 2)
        EndSwitch
    Next
    Return $SDATA
EndFunc   ;==>__URIENCODE


Func __lGUI()
    Local $llol, $SLIS
    $SLIS = StringSplit(__LISLll(), ";")
    For $i = 1 To $SLIS[0]
        $llol &= StringLeft($SLIS[$i], StringInStr($SLIS[$i], "|"))
    Next
    Return $llol
EndFunc   ;==>__lGUI

Func LISL()
    Local $langlis = "Arabic|ar;English|en;French|fr"
    Return $langlis
EndFunc   ;==>LISL

Func __LISLll()
    Local $langlist = "Afrikaans|af;Albanian|sq;Arabic|ar;Armenian|hy;Azerbaijani|az;Basque|eu;Belarusian|be;Bengali|bn;Bulgarian|bg;Catalan|ca;Chinese|zh-CN;Croatian|hr;Czech|cs;Danish|da;Dutch|nl;English|en;Esperanto|eo;" & _
            "Estonian|et;Filipino|tl;Finnish|fi;French|fr;Galician|gl;Georgian|ka;German|de;Greek|el;Gujarati|gu;Haitian Creole|ht;Hebrew|iw;Hindi|hi;Hungarian|hu;Icelandic|is;Indonesian|id;Irish|ga;Italian|it;" & _
            "Japanese|ja;Kannada|kn;Khmer|km;Korean|ko;Lao|lo;Latin|la;Latvian|lv;Lithuanian|lt;Macedonian|mk;Malay|ms;Maltese|mt;Norwegian|no;Persian|fa;Polish|pl;Portuguese|pt;Romanian|ro;Russian|ru;" & _
            "Serbian|sr;Slovak|sk;Slovenian|sl;Spanish|es;Swahili|sw;Swedish|sv;Tamil|ta;Telugu|te;Thai|th;Turkish|tr;Ukrainian|uk;Urdu|ur;Vietnamese|vi;Welsh|cy;Yiddish|yi"
    Return $langlist
EndFunc   ;==>__LISLll
Func __EXIT()
    Exit
EndFunc   ;==>__EXIT
Edited by Mrbenkali
Link to comment
Share on other sites

  • 3 weeks later...
  • 7 months later...

 

updat : :support any language "arabic :shifty:right characters " and read a long string

Opt("GUIONEVENTMODE", 1)
Global $link = "http://translate.google.com/"
Global $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
Global $TITEL = "Google Translate"

Global $SCRIPTGUI = GUICreate($TITEL, 841, 448, -1, -1, -2133983232)
GUISetOnEvent(-3, "__EXIT")
Global $EDIT1 = GUICtrlCreateEdit("", 0, 0, 841, 156)
GUICtrlSetResizing(-1, 774)
Global $Edit2 = GUICtrlCreateEdit("", 0, 160, 841, 260)
GUICtrlSetFont(-1, 15, 400, 0, "Arial")
GUICtrlSetResizing(-1, 870)
Global $Label1 = GUICtrlCreateLabel("Detec lang : ", 23, 425, 180, 17)
GUICtrlSetResizing(-1, 834)
GUICtrlCreateLabel("translate to ", 155, 425, 59, 17)
GUICtrlSetResizing(-1, 834)
Global $COMBO1 = GUICtrlCreateCombo("", 215, 423, 127, 25, 2097155)
GUICtrlSetOnEvent($COMBO1, "__GOTRAN")
GUICtrlSetData($COMBO1, __lGUI())
GUICtrlSetResizing(-1, 834)
Global $BUTTON1 = GUICtrlCreateButton("Speak", 352, 421, 75, 25)
GUICtrlSetOnEvent($BUTTON1, "__GOSPEAK")
GUICtrlSetResizing(-1, 834)
GUISetState()

While True
    Sleep(1000)
WEnd

Func __GOSPEAK()
    Local $readtxt
    $readtxt = GUICtrlRead($Edit2)
    If $readtxt = "" Then Return
    WinSetTitle($SCRIPTGUI, "", "WAIT DOWNLOAD DATA...")
    __GOOGLESPEEK($readtxt)
    WinSetTitle($SCRIPTGUI, "", $TITEL)
EndFunc   ;==>__GOSPEAK
Func __GOTRAN()
    Local $readtxt = GUICtrlRead($EDIT1)
    If $readtxt = "" Then Return
    WinSetTitle($SCRIPTGUI, "", "WAIT DOWNLOAD DATA...")
    __GOOGLETRANS($readtxt)
    WinSetTitle($SCRIPTGUI, "", $TITEL)
EndFunc   ;==>__GOTRAN
Func __GOOGLETRANS($TEXTTOTRANS)
    Local $TXT, $STEXT1, $STEXT, $STEXT2, $STEXT3, $STEXT4, $STEXT5, $Autodetlang
    
    $Autodetlang = __DETLANG(StringLeft(StringRegExpReplace($TEXTTOTRANS, "\r\n|\r|\n", Chr(32)), 33))

    $Autodetlang = __SLANG($Autodetlang)
    
    GUICtrlSetData($Label1, "Detec lang : " & $Autodetlang)
    
    $Gettrnlang = __SLANG(GUICtrlRead($COMBO1), 1)
    
    If StringInStr("ar fa iw ur yi", $Gettrnlang) > 0 Then
        GUICtrlSetStyle($Edit2, 3152064 + 2)
    Else
        GUICtrlSetStyle($Edit2, 3152064 + 0)
    EndIf
    
    GUICtrlSetData($Edit2, "")
    $STEXT = StringSplit($TEXTTOTRANS, @CRLF, 1)
    For $i = 1 To $STEXT[0]
        $STEXT1 = StringSplit($STEXT[$i], Chr(32), 1)
        For $O = 1 To $STEXT1[0]
            $TXT &= $STEXT1[$O] & Chr(32)
            If StringLen($TXT) > 90 Or $O = $STEXT1[0] Then
                $STEXT2 = StringSplit($TXT, ".")
                For $z = 1 To $STEXT2[0]
                    $STEXT3 = StringSplit($STEXT2[$z], '"')
                    For $L = 1 To $STEXT3[0]
                        $STEXT4 = StringSplit($STEXT3[$L], '?')
                        For $M = 1 To $STEXT4[0]
                            $STEXT5 = StringSplit($STEXT4[$M], '!')
                            For $S = 1 To $STEXT5[0]
                                if StringIsSpace($STEXT5[$S]) Then ContinueLoop
                                _Guisetdata(__TRANTXT($STEXT5[$S], $Gettrnlang))
                                $TXT = ""
                                If $S <> $STEXT5[0] Then _Guisetdata('!')
                            Next
                            If $M <> $STEXT4[0] Then _Guisetdata('?')
                        Next
                        If $L <> $STEXT3[0] Then _Guisetdata('"')
                    Next
                    If $z <> $STEXT2[0] Then _Guisetdata(".")
                Next
            EndIf
        Next
        If $i <> $STEXT[0] Then _Guisetdata(@CRLF)
    Next
EndFunc   ;==>__GOOGLETRANS
Func __SLANG($LANGG, $OOPT = 2)
    Local $OPT = 2
    Local $SLIS = StringSplit(__LISLll(), ";")
    For $i = 1 To $SLIS[0]
        Local $GETl = StringSplit($SLIS[$i], "|")
        If StringInStr($GETl[$OOPT], $LANGG, 2) Then
            If $OOPT = 2 Then $OPT = 1
            Return $GETl[$OPT]
        EndIf
    Next
EndFunc   ;==>__SLANG
Func __TRANTXT($TXT, $tto)
    Local $ENCODESSTRING, $READ, $DATA
    $ENCODESSTRING = __URIENCODE($TXT)
    $READ = __DOWN($link & "translate_a/t?client=t&sl=auto&text=" & $ENCODESSTRING & "&tl=" & $tto)
    $DATA = StringSplit($READ, '"')
    Return $DATA[2]
EndFunc   ;==>__TRANTXT
Func REV($TXT)
    Local $split, $LOL
    $split = StringSplit($TXT, " ", 1)
    For $i = $split[0] To 1 Step -1
        $LOL &= $split[$i] & " "
    Next
    Return $LOL
EndFunc   ;==>REV
Func _Guisetdata($text)
    GUICtrlSetData($Edit2, GUICtrlRead($Edit2) & $text & " ")
EndFunc   ;==>_Guisetdata
Func __GOOGLESPEEK($TEXTTOSPEEK)
    Local $TXT, $OPEN, $STEXT1, $READ = "", $ENCODESSTRING, $RESTRING, $LANG, _
            $MPFIL = FileGetShortName(@ScriptDir) & "\" & GUICtrlRead($COMBO1) & "__" & Random(1, 99, 1) & ".MP3"
    
    $RESTRING = StringRegExpReplace($TEXTTOSPEEK, "\r\n|\r|\n", " ")
    
    $LANG = __DETLANG(StringLeft($RESTRING, 33))
    
    $OPEN = FileOpen($MPFIL, 18)
    $STEXT1 = StringSplit($RESTRING, " ", 1)
    For $O = 1 To $STEXT1[0]
        $TXT &= $STEXT1[$O] & " "
        If StringLen($TXT) > 90 Or $O = $STEXT1[0] Then
            $ENCODESSTRING = __URIENCODE($TXT)
            FileWrite($OPEN, InetRead($link & "translate_tts?ie=UTF-8&tl=" & $LANG & "&q=" & $ENCODESSTRING, 1))
            $TXT = ""
        EndIf
    Next
    FileClose($OPEN)
    
    SoundPlay($MPFIL)
EndFunc   ;==>__GOOGLESPEEK
Func __DETLANG($STRI)
    Local $TST, $LANGGG
    $STRI = __URIENCODE($STRI)
    $TST = __DOWN($link & "translate_a/t?client=t&sl=auto&text=" & $STRI)
    $LANGGG = StringLeft(StringTrimLeft($TST, StringInStr($TST, '[["', 0, -1) + 2), 2)
    Return $LANGGG
EndFunc   ;==>__DETLANG
Func __DOWN($URL)
    $oHTTP.Open("GET", $URL, False)
    $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1")
    $oHTTP.Send("")
    $oReceived = $oHTTP.ResponseText
    Return $oReceived
EndFunc   ;==>__DOWN
Func __URIENCODE($SDATA)
    Local $ADATA = StringSplit(BinaryToString(StringToBinary($SDATA, 4), 1), "")
    Local $NCHAR
    $SDATA = ""
    For $i = 1 To $ADATA[0]
        $NCHAR = Asc($ADATA[$i])
        Switch $NCHAR
            Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126
                $SDATA &= $ADATA[$i]
            Case 32
                $SDATA &= "+"
            Case Else
                $SDATA &= "%" & Hex($NCHAR, 2)
        EndSwitch
    Next
    Return $SDATA
EndFunc   ;==>__URIENCODE


Func __lGUI()
    Local $llol, $SLIS
    $SLIS = StringSplit(__LISLll(), ";")
    For $i = 1 To $SLIS[0]
        $llol &= StringLeft($SLIS[$i], StringInStr($SLIS[$i], "|"))
    Next
    Return $llol
EndFunc   ;==>__lGUI

Func LISL()
    Local $langlis = "Arabic|ar;English|en;French|fr"
    Return $langlis
EndFunc   ;==>LISL

Func __LISLll()
    Local $langlist = "Afrikaans|af;Albanian|sq;Arabic|ar;Armenian|hy;Azerbaijani|az;Basque|eu;Belarusian|be;Bengali|bn;Bulgarian|bg;Catalan|ca;Chinese|zh-CN;Croatian|hr;Czech|cs;Danish|da;Dutch|nl;English|en;Esperanto|eo;" & _
            "Estonian|et;Filipino|tl;Finnish|fi;French|fr;Galician|gl;Georgian|ka;German|de;Greek|el;Gujarati|gu;Haitian Creole|ht;Hebrew|iw;Hindi|hi;Hungarian|hu;Icelandic|is;Indonesian|id;Irish|ga;Italian|it;" & _
            "Japanese|ja;Kannada|kn;Khmer|km;Korean|ko;Lao|lo;Latin|la;Latvian|lv;Lithuanian|lt;Macedonian|mk;Malay|ms;Maltese|mt;Norwegian|no;Persian|fa;Polish|pl;Portuguese|pt;Romanian|ro;Russian|ru;" & _
            "Serbian|sr;Slovak|sk;Slovenian|sl;Spanish|es;Swahili|sw;Swedish|sv;Tamil|ta;Telugu|te;Thai|th;Turkish|tr;Ukrainian|uk;Urdu|ur;Vietnamese|vi;Welsh|cy;Yiddish|yi"
    Return $langlist
EndFunc   ;==>__LISLll
Func __EXIT()
    Exit
EndFunc   ;==>__EXIT

Thank you, DjForfun, your code worked very well and exactly.

Can I used your code as an UDF in my script?

Thank you very much! :)

Link to comment
Share on other sites

  • 1 month later...

Hi,

This was not working for me, till I updated the function _GoogleTranslateString():

Func _GoogleTranslateString($sText,$sLangPair= -1,$bEncodeURL=False )
    Local $url, $sTemp, $aTranslated, $sTranslated
    If $sLangPair = -1 Then $sLangPair = "en|es"
    $regex= '(?:<(?i)DIV id="?result_box"? dir="?ltr"?>)(.*?)(?:</(?i)DIV>)'
    $sTemp = $sText
    If $bEncodeURL Then
        $sTemp = _URLEncode($sText)
    EndIf
    $url =StringFormat('http://google.com/translate_t?langpair=%s&text=%s',$sLangPair,$sTemp)
    If(InetGet($url,".temp.html",1)) Then

        $aTranslated = StringRegExp(StringStripWS(FileRead(".temp.html"),7),$regex,3)
        If IsArray($aTranslated) Then
            FileDelete(".temp.html")
            $sTranslated = StringReplace($aTranslated[0],Chr(160),Chr(32))
            $sTranslated = StringRegExpReplace($sTranslated,"((\s|\n)?<(?i)br)(.*?)(>)(\s)",@CRLF)

            If $bEncodeURL Then
                Return _URLDecode($sTranslated)
            EndIf
            Return $sTranslated
        
;Change starts here
    Else
            ConsoleWrite("Translation is no array" & @CRLF)
            $aTranslated = StringStripWS(FileRead(".temp.html"),7)
            if StringInStr($aTranslated, 'onmouseout="this.style.backgroundColor=' & "'#fff'" & '">')>0 Then
                $aTranslated = StringSplit($aTranslated, 'onmouseout="this.style.backgroundColor=' & "'#fff'" & '">', 1)[2]
                $aTranslated = StringSplit($aTranslated, "</span>", 1)[1]
                Local $strg = $aTranslated
                If $bEncodeURL Then
                    Return _URLDecode($strg)
                EndIf
                Return $strg
            EndIf
        EndIf
    EndIf
    Return SetError(1,0,$sText)
EndFunc

The change is because StringRegExp did not return an array. Now it works for me.

Link to comment
Share on other sites

  • 2 months later...

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
 Share

  • Recently Browsing   0 members

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