asp+|xml| website | multi-language
Create a new XML file with two storage language entries and put it in the languages directory:
Zh-cn.xml
The following is a reference fragment:
<?xml version= "1.0" encoding= "Utf-8"?>
<Languages>
<aboutus> About Us </aboutus>
<product> Product Show </product>
</Languages> |
English.xml
The following is a reference fragment:
<?xml version= "1.0" encoding= "Utf-8"?>
<Languages>
<aboutus>about us</aboutus>
<product>Products</product>
</Languages> |
Common function (method) functions.asp, placed in the Comm directory:
The following is a reference fragment:
<%
’-------------------
' Function name: Getlang ();
' parameter lang: current language;
' Parameter litem: Set the language term;
' Example: Call Getlang ("ZH-CN", "AboutUs");
' Author:huerreson,huerreson@msn.com
’-------------------
Function Getlang (ByVal lang,litem)
Dim xmldom
If Objcheck ("Microsoft.XMLDOM") Then
Set xmldom = Server.CreateObject ("Microsoft.XMLDOM")
ElseIf Objcheck ("Microsoft.XMLDOM") Then
Set xmldom = Server.CreateObject ("MSXML2. DOMDocument ")
Else
Response.Write (the server does not support Microsoft.) Xmldom ' and ' MSXML2. DOMDocument ', cannot use this feature ')
End If
Xmldom.async = False
Xmldom.load (Server.MapPath ("languages/" & Lang & ". xml"))
Response.Write (XmlDom.documentElement.selectSingleNode (Litem). Text)
Set xmldoc = Nothing
Set xmldom = Nothing
End Function
’-------------------
' Function name: Objcheck ();
' parameter objname: object name;
' Example: Call Objcheck ("Microsoft.XMLDOM");
' Author:huerreson,huerreson@msn.com
’-------------------
Function Objcheck (objname)
On Error Resume Next
Objcheck = False
Set OBJ = Server.CreateObject (objname)
If-2147221005 <> ERR Then
Objcheck = True
End If
Set OBJ = Nothing
End Function
%> |
asp+xml Implementation of multi-language Web site application Examples:
the following is a reference fragment:
<!--
= = Multi-Language version solution = =
Author: huerrseon,huerreson@msn.com
-->
<% @LANGUAGE = "VBSCRIPT" codepage= "65001"%>
<!-- #include file= "comm/functions.asp" -->
<style type= "Text/css" >
#NavMenu { border-bottom:1px dashed #000;}
</style>
<%
dim langquery
Langquery = lcase (Request.QueryString ("Lang")
if not (IsNull (langquery) or LangQuery = "") then
langquery = langquery
Else
LangQuery = "Default"
end if
%>
<div id= "Navmenu" ><%call getlang (Langquery, "AboutUs")%></ Div>
<div id= "Switchlangbar" > Language switching <a href= "? LANG=ZH-CN" > Simplified Chinese </a>--<a href= "? Lang=english" >ENGLSIH</A></DIV> |