ASP using Google to achieve online translation function _ Application skills

Source: Internet
Author: User
Sometimes you want to provide multi-language support for our web pages, and if one language is too cumbersome to do with a single Web page, it is fortunate that Google offers the Language Tools feature, and here's how to use it to translate between multiple languages on a Web page.
Copy Code code as follows:

<form>
<select name= "LAN" >
<option value= "En|de" > English translation into German </option>
<option value= "En|es" > English translation into Spanish </option>
<option value= "EN|FR" > English translation into French </option>
<option value= "En|it" > English translation into Italian </option>
<option value= "en|pt" > English translation into Portuguese </option>
<option value= "En|ja" > English translation into Japanese beta</option>
<option value= "En|ko" > English translated into Korean beta</option>
<option value= "EN|ZH-CN" > English translation into Chinese (Simplified) beta</option>
<option value= "De|en" > German translated into English </option>
<option value= "De|fr" > German translated into French </option>
<option value= "Es|en" > Spanish translated into English </option>
<option value= "Fr|en" > French translation into English </option>
<option value= "Fr|de" > French translated into German </option>
<option value= "It|en" > Italian translated into English </option>
<option value= "Pt|en" > Portuguese translated into English </option>
<option value= "Ja|en" > Japanese translation into English beta</option>
<option value= "Ko|en" > Korean translated into 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 the lan.htm is used to select the language to be translated, including the original language and the language to be translated. All we need to do is copy the contents of the lan.htm to the page that provides the multilingual translation.
Copy Code code as follows:

<title> Online Translator </title>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">

<body>
<%
' On Error Resume Next
' If the speed is slow, you can adjust the following time. Per 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

The position in another string where the ' fetch ' string appears
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= "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>

Translate.asp implements the translation function, which is achieved by using Google's language tools.
Note that the encoding used for translate.asp files is "Utf-8" that supports all characters because it provides multilanguage support
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.