inicio mail me! sindicaci;ón

Realize the function that online article translates with ASP

Think the webpage that is us provides multilingual support occasionally, if a kind of language uses a piece of webpage to do honest too troublesome, fortunately Google provided language tool function, how does the introduction use it to realize a webpage below the changeover between a variety of languages.

Lan.htm

It is quotative content below:
<form>
<select Name= "lan ">
<option Value= "en | De" > English is translated into German </option>
<option Value= "en | Es" > English is translated into spanish </option>
<option Value= "en | Fr" > English is translated into French </option>
<option Value= "en | It" > English is translated into Italian </option>
<option Value= "en | Pt" > English is translated into Portuguese </option>
<option Value= "en | Ja" > English translates BETA</option of language of the whole day>
<option Value= "en | Ko" > English is translated into Korea language BETA</option>
<option Value= "en | Zh-CN" > English is translated into Chinese (simplified) BETA</option>
<option Value= "de | En" > Germanization becomes English </option>
<option Value= "de | Fr" > Germanization becomes French </option>
<option Value= "es | En" > spanish is translated into English </option>
<option Value= "fr | En" > French is translated into English </option>
<option Value= "fr | De" > French is translated into German </option>
<option Value= "it | En" > Italian is translated into English </option>
<option Value= "pt | En" > portuguese is translated into English </option>
<option Value= "ja | En" > Japanese is translated into English BETA</option>
<option Value= "ko | Language of En" > Korea is translated into English BETA</option>
<option Value= "zh-CN | En" > Chinese (simplified) the interpreter becomes English BETA</option>
<input Style= "FONT-SIZE: 12px" Type= "button" Value= "Go->" Name= "Button1" OnClick= "javascript:wIndow.open(’translate.asp? Urls=’ document.location ‘&lan=’ lan.value, ‘_self’ , ”) “>
</select>
</form>

The language that the content in Lan.htm uses a choice to want an interpreter includes original language and the language that should translate. It is OK that we need to the content beat in Lan.htm the content beat in Lan.htm arrives in the page that offers multilingual translation only.

Translate.asp

It is quotative content below:

<html>
<head>
</title of <title> online interpreter>
<meta Http-equiv= "Content-Type" Content= "text/html; Charset=utf-8 ">
</head>
<body>
<%
‘on Error Resume Next
‘ if net fast very slow word, can adjust the following time. Unit second
Server.ScriptTimeout = 999999
‘========================================================
Function of ‘ character encode
‘========================================================
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
‘ takes a string the occurrence position in another string
Function Newstring(wstr, strng)
Newstring=Instr(lcase(wstr) , lcase(strng) ) If Newstring<=0 Then Newstring=Len(wstr)
End Function
‘ replaces string functionFunction 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= “” ) ThenElseStart=Newstring(ReadXml, start)
ReadXml=mid(ReadXml, start)Ends=Newstring(ReadXml, ends)
ReadXml=left(ReadXml, ends-1)End IfEnd FunctionDim Urlpage, lanUrlpage=request(”urls” )Lan=request(”lan” )
%>
<form Method= "post" Action= "translate.asp ">
<input Type= "text" Name= "urls" Size= "150" Value= "<%=urlpage%> ">
<input Type= "hidden" Name= "lan" Value= "<%=lan%> ">
<input Type= "submit" Value= "submit ">
</form>
<%Dim TransURLTransURL= “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) ThenGetcont=ReadXml(transURL, “Gb2312″ , “” , “” ,, Response.Write(getcont)End If
%>
</body>
</html>

Translate.asp implementation translates a function, this is the language tool implementation that uses Google.

Attention, because provide multilingual support, the code that so Translate.asp file place uses is the “utf-8 that supports all character “

Bookmark:Digg Del.icio.us Reddit

Leave a Comment