Sometimes we want to provide multi-language support for our web pages. It is too troublesome to use one web page for one language. Fortunately, Google provides a language tool function. Here is how to use it to convert web pages between multiple languages. .
Author: Taote.com
Source: http://www.tot.name
Note: Please indicate the source for reprinting
lan.htm
<form>
<select name="lan">
<option value="en|de">English to German</option>
<option value="en|es">English to Spanish</option>
<option value="en|fr">English to French</option>
<option value="en|it">English to Italian</option>
<option value="en|pt">English to Portuguese</option>
<option value="en|ja">English to Japanese BETA</option>
<option value="en|ko">English to Korean BETA</option>
<option value="en|zh-CN" >English translated into Chinese (Simplified) BETA</option>
<option value="de|en">German to English translation</option>
<option value="de|fr">German to French translation</option>
<option value="es|en">Spanish to English</option>
<option value="fr|en">French to English</option>
<option value="fr|de">French to German</option>
<option value="it|en">Italian to English</option>
<option value="pt|en">Portuguese to English</option>
<option value="ja|en">Japanese to English BETA</option>
<option value="ko|en">Korean to English BETA</option>
<option value="zh-CN|en">Chinese (Simplified) translated into 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 content in lan.htm is used to select the language to be translated, including the original language and the language to be translated. We only need to copy the content in lan.htm to the page that provides multi-language translation.
translate.asp
<html>
<head>
<title>Online Translation</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
'on error resume next
' If the Internet speed is very slow, you can adjust the following time. Unit second
Server.ScriptTimeout = 999999
'================================================== =======
'Character encoding function
'================================================== =======
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
'Get the occurrence position of a line string in another string
Function Newstring(wstr,strng)
Newstring=Instr(lcase(wstr),lcase(strng))
if Newstring<=0 then Newstring=Len(wstr)
End Function
'Replace string 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")
%>
<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 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
%>
</body>
</html>
translate.asp implements the translation function, which is implemented using Google's language tools.
Note that because multi-language support is provided, the encoding used in the translate.asp file is "utf-8" that supports all characters.