Online article translation function in ASP program

Source: Internet
Author: User
Tags end string
program | online | Online Sometimes you want to provide multi-language support for our web pages, and if one language is too cumbersome to do with a Web page, it is fortunate that Google offers the Language Tools feature, and here's how to use it to convert multiple languages across a Web page.

Lan.htm

<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 translation into Korean BETA </option>
<option value= "EN|ZH-CN" > English translation into Chinese (Simplified) BETA </option>
<option value= "De|en" > German translation into English </option>
<option value= "DE|FR" > German translation 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 translation into German </option>
<option value= "It|en" > Italian translated into English </option>
<option value= "Pt|en" > Portuguese translation into English </option>
<option value= "Ja|en" > Japanese translation into English BETA </option>
<option value= "Ko|en" > Korean translation 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"
</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.

Translate.asp

<title> Online Translation </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 because of the multi-language support, the encoding used by the translate.asp file is to support all characters "utf-



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.