Copy codeThe Code is as follows: Sometimes we want to provide multi-language support for our web pages. It is too troublesome to use a web page in one language. Fortunately, Google provides the language tool function, the following describes how to use it to convert web pages into multiple languages.
Lan.htm
<Form>
<Select name = "lan">
<Option value = "en | de"> English translation to German </option>
<Option value = "en | es"> translating English into Spanish </option>
<Option value = "en | fr"> translate English into French </option>
<Option value = "en | it"> translating English into Italian </option>
<Option value = "en | pt"> translate English into Portuguese </option>
<Option value = "en | ja"> translating English into Japanese BETA </option>
<Option value = "en | ko"> translating English into Korean BETA </option>
<Option value = "en | zh-CN"> translating English into Chinese (simplified) BETA </option>
<Option value = "de | en"> translate German into English </option>
<Option value = "de | fr"> translate German into French </option>
<Option value = "es | en"> translating Spanish into English </option>
<Option value = "fr | en"> translate French into English </option>
<Option value = "fr | de"> translate French into German </option>
<Option value = "it | en"> translating Italian into English </option>
<Option value = "pt | en"> translate Portuguese into English </option>
<Option value = "ja | en"> translating Japanese into English BETA </option>
<Option value = "ko | en"> translating Korean into English BETA </option>
<Option value = "zh-CN | en"> Translating Chinese (simplified) 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 can simply copy the content in lan.htm to a page that provides multilingual 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 network speed is slow, you can adjust the following time. Unit: seconds
Server. ScriptTimeout = 999999
"============================================== ========================
"Character encoding Functions
"============================================== ========================
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
"Position where the row string appears in another string
Function Newstring (wstr, strng)
Newstring = Instr (lcase (wstr), lcase (strng ))
If Newstring <= 0 then Newstring = Len (wstr)
End Function
"Replacing string functions
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 the translate. asp file is encoded with UTF-8, which supports all characters"