ちょっと作ってみた。かなりの手抜き版だけどね
pos 10,10
sdim text1, 8*1024
text1 = "ここに翻訳したい文章を入力してください。"
mesbox text1, 500, 200 : oi_text1 = stat
cx = ginfo_cx : cy = ginfo_cy
pos cx, cy : button gosub " 翻訳 ", *honyaku
pos cx+100, cy : button gosub " クリア ", *clear
pos cx+200, cy : combox mode,,"英→日\n日→英"
pos cx, ginfo_cy
sdim text2, 8*1024
mesbox text2, 500, 200 : oi_text2 = stat
stop
*clear
objprm oi_text1, ""
objprm oi_text2, ""
return
*honyaku
if(busy) { return }
busy = 1
objprm oi_text2, "翻訳中・・・"
newcom HTTP, "MSXML2.XMLHTTP"
if( varuse(HTTP) == 0 ) { dialog "MSXML2.XMLHTTP の初期化に失敗" : end }
newcom ADOS, "ADODB.Stream"
if( varuse(ADOS) == 0 ) { dialog "ADODB.Stream の初期化に失敗" : end }
newcom ScriptControl, "ScriptControl"
if( varuse(ScriptControl) == 0 ) { dialog "ScriptControl の初期化に失敗" : end }
ScriptControl("Language") = "JScript"
eid = "CR-EJ", "CR-JE"
form_data = ""
form_data += ScriptControl("Run","encodeURIComponent", "both") + "=" + ScriptControl("Run","encodeURIComponent", "TH")
form_data += "&"
form_data += ScriptControl("Run","encodeURIComponent", "text") + "=" + ScriptControl("Run","encodeURIComponent", text1)
form_data += "&"
form_data += ScriptControl("Run","encodeURIComponent", "clearFlg") + "=" + ScriptControl("Run","encodeURIComponent", "1")
form_data += "&"
form_data += ScriptControl("Run","encodeURIComponent", "eid") + "=" + ScriptControl("Run","encodeURIComponent", eid(mode))
form_data += "&"
form_data += ScriptControl("Run","encodeURIComponent", "trn_textText") + "=" + ScriptControl("Run","encodeURIComponent", " ")
ADOS->"Open"
ADOS("Charset") = "ascii"
ADOS->"WriteText" form_data
ADOS("Position") = 0
ADOS("Type") = 1
pd = ADOS(".Read")
ADOS->"Close"
url = "http://honyaku.yahoo.co.jp/transtext"
HTTP->"Open" "POST", url, 1
HTTP->"SetRequestHeader" "Content-Type", "application/x-www-form-urlencoded"
HTTP->"Send" pd
repeat 10 * 30 ;timeout 30秒
wait 10
if( HTTP("readyState") == 4 ) { break }
loop
if( HTTP("readyState") == 4 ) {
s = HTTP("responseText")
;2つ目のTEXTAREAの中身抽出のつもり…手抜きだけど
mark = "<textarea "
s = strmid(s, instr(s, 0, mark)+strlen(mark), 0x7FFFFFFF)
mark = "<textarea "
s = strmid(s, instr(s, 0, mark)+strlen(mark), 0x7FFFFFFF)
mark = ">"
s = strmid(s, instr(s, 0, mark)+strlen(mark), 0x7FFFFFFF)
mark = "</textarea>"
s = strmid(s, 0, instr(s, 0, mark))
objprm oi_text2, s
}
else {
HTTP->"Abort"
objprm oi_text2, "▲タイムアウトしました"
}
HTTP = 0
ADOS = 0
ScriptControl = 0
busy = 0
return
Yahoo翻訳はUTF8だから、JScriptのencodeURIComponent使って手抜きしてみた。
他のエンコードだと、もう少し手間が必要になる。