谷歌在线翻译源码
官方论坛脚本,暂只支持英文翻译其它语言,代码如下: #Region - Demo _GoogleToMsgBox("Hello World", "en", "en") _GoogleToMsgBox("Hello World", "en", "ja") _GoogleToMsgBox("Hello World", "en", "es") _GoogleToMsgBox("Hello World", "en", "it") _GoogleToMsgBox("Hello World", "en", "zh-cn") _GoogleToMsgBox("Hello World", "en", "ar") _GoogleToMsgBox("Hello World", "en", "bg") _GoogleToMsgBox("Hello World", "en", "fr") _GoogleToMsgBox("Hello World", "en", "de") _GoogleToMsgBox(InputBox("在线快速翻译", "请输入您要翻译的内容", ""), "en", "zh-cn") Func _GoogleToMsgBox($sText, $sFrom, $sTo) Msgbox(4096, "在线快速翻译 [" & $sFrom & ":" & $sTo & "]", $sText & @TAB & @TAB & @TAB & @CRLF & @CRLF & _GoogleTranslate($sText, $sFrom, $sTo)) EndFunc #EndRegion 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 |
<< 天气预报SMTP 邮件发送工具 >>
查看所有评论

