Jump to content

Using AutoIt to build a translation model


forkinpm
 Share

Recommended Posts

If you don't know well AutoIt I suggest to start read some finished projects.

Look here

Func _GoogleTranslate($sText, $sFrom = "en", $sTo = "ja")
    Local Const $FileName = "Translation.jsn"
    Local Const $Pattern = '"translatedText":"([^"]+)"'
    Local $GoogleURL = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=%s&langpair=%s%%7C%s"
    Local $File
    $GoogleURL = StringFormat($GoogleURL, $sText, $sFrom, $sTo)
    If Not InetGet($GoogleURL, $FileName, 1) Then Return SetError(1, 0, 0)
    $File = FileOpen($FileName, 4)
    FileGetSize($FileName)
    $Translation = FileRead($File, FileGetSize($FileName))
    FileClose($File)
    FileDelete($FileName)
    $Translation = BinaryToString($Translation, 4)
    If StringRegExp($Translation , $Pattern) Then
        $Translation = StringRegExp($Translation , $Pattern, 1)
        $Translation = $Translation[0]
        Return $Translation
    EndIf
EndFunc

MsgBox(0,"",_GoogleTranslate("Hello World", "en", "de"))

When the words fail... music speaks.

Link to comment
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
 Share

  • Recently Browsing   0 members

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