ASP uses Google to implement online translation

Source: Internet
Author: User

Sometimes we want to provide multi-language support for our web pages. It would be too troublesome to use one 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. Copy codeThe Code is as follows: <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.Copy codeThe Code is as follows: <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
'Replacement 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 the translate. asp file is encoded with UTF-8, which supports all characters"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.