您现在的位置是:网站首页> 编程资料编程资料
A利用ASP小偷和Google实现在线翻译功能的代码_应用技巧_
2023-05-25
318人已围观
简介 A利用ASP小偷和Google实现在线翻译功能的代码_应用技巧_
复制代码 代码如下:
有时候想为我们的网页提供多语言支持,如果一种语言用一张网页来做实在太麻烦了,幸好Google提供了语言工具功能,下面介绍如何利用它来实现网页多种语言之间的转换。
lan.htm
lan.htm中的内容用来选择要翻译的语言包括原来的语言和要翻译成的语言。我们只需要将lan.htm中的内容拷到提供多语言翻译的页面中就可以了。
translate.asp
<%
"on error resume next
" 如果网速很慢的话,可以调整以下时间。单位秒
Server.ScriptTimeout = 999999
"========================================================
"字符编码函数
"========================================================
Function BytesToBstr(body,code)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset =code
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
"取行字符串在另一字符串中的出现位置
Function Newstring(wstr,strng)
Newstring=Instr(lcase(wstr),lcase(strng))
if Newstring<=0 then Newstring=Len(wstr)
End Function
"替换字符串函数
function ReplaceStr(ori,str1,str2)
ReplaceStr=replace(ori,str1,str2)
end function
"=====================================================
function ReadXml(url,code,start,ends)
set oSend=createobject("Microsoft.XMLHTTP")
SourceCode = oSend.open ("GET",url,false)
oSend.send()
ReadXml=BytesToBstr(oSend.responseBody,code )
if(start="" or ends="") then
else
start=Newstring(ReadXml,start)
ReadXml=mid(ReadXml,start)
ends=Newstring(ReadXml,ends)
ReadXml=left(ReadXml,ends-1)
end if
end function
dim urlpage,lan
urlpage=request("urls")
lan=request("lan")
%>
<%
dim transURL
transURL="http://216.239.39.104/translate_c?hl=zh-CN&ie=UTF-8&oe=UTF-8&langpair="&server.URLEncode(lan)&"&u="&urlpage&"&prev=/language_tools"
if(len(urlpage)>3) then
getcont=ReadXml(transURL,"gb2312","","")
response.Write(getcont)
end if
%>
translate.asp实现翻译功能,这是利用google的语言工具实现的。
注意,因为提供多语言支持,所以translate.asp文件所用的编码是支持所有字符的"utf-8"
