新建两个存储语言项的xml文件,放到Languages目录下:
zh-cn.xml
以下是引用片段:
关于我们
产品展示
english.xml
以下是引用片段:
About us
Products
公用函数(方法)Functions.asp,放到Comm目录下:
以下是引用片段:
<%
’-------------------
’函数名:getLang();
’参数Lang:当前语言;
’参数Litem:设定的语言项;
’示例: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("服务器不支持’Microsoft.XMLDOM’及’MSXML2.DOMDocument’,无法使用本功能")
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
’-------------------
’函数名:objCheck();
’参数ObjName:对象名称;
’示例: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实现多语言网站应用实例:
以下是引用片段:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim LangQuery
LangQuery = lCase(Request.QueryString("lang"))
If Not (IsNull(LangQuery) or LangQuery = "") Then
LangQuery = LangQuery
else
LangQuery = "default"
End if
%>
<%Call getLang(LangQuery,"aboutus")%><>
语言切换简体中文--Englsih<>
关键字词: