Recommended: ASP basic tutorial: Other commonly used components of ASP When you use ASP to write server-side applications, you must rely on ActiveX components to powerful web applications' functions, such as: you need to connect to the database, operate the database online, etc. 1. Browser Capabilities components are well known and do not
Sometimes I 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 language tool functions. The following describes how to use it to convert web pages between multiple languages.
lan.htm
| The following is the quoted content: <form> <select name=lan> <option value=en|de>English to 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 Chinese) BETA</option> <option value=de|en>German to English</option> <option value=de|fr>German to French</option> <option value=es|en>Spanish translation 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 to English</option> <option value=pt|en>Portuguese translation into English</option> <option value=ja|en>Japanese to English BETA</option> <option value=ko|en>Korean translation into English BETA</option> <option value=zh-CN|en>Chinese (simplified) Translation 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 into. We just need to copy the content in lan.htm to a page that provides multilingual translation.
translate.asp
| The following is the quoted content: <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 seconds 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 'Fetch the line string's occurrence position in another string Function Newsstring(wstr,strng) Newsstring=Instr(lcase(wstr),lcase(strng)) if Newsstring<=0 then Newsstring=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 translation function, which is implemented using Google's language tools.
Note that because multilingual support is provided, the encoding used by the translate.asp file is utf-8 that supports all characters.
Share: Make the pop-up window "obedient" a little Popups will appear when entering some websites while surfing the Internet. It may be a kind greeting from the webmaster to you, or it may be an important announcement of the website, website advertisements, etc. But if you use it poorly, it will make people feel bored. How to make pop-ups work without affecting browsing