多语言版本的测试

    public static string GetLanguage(int filetype,string key)//filetype分两种:用户,管理员
    {
        int cache = 0;//1=开启缓存
        string path = "Language/zh-cn/user.xml";
        if (filetype == 1)//管理员
        {
            path = "Language/zh-cn/admin.xml";
        }
        object o = null;
        Hashtable hash = new Hashtable();
        if (System.Web.HttpContext.Current.Cache[path] == null || cache == 0)//从未被加载
        {
            XmlDocument d = new XmlDocument();
            d.Load(System.Web.HttpContext.Current.Server.MapPath(path));        
            foreach (XmlNode xn in d.SelectSingleNode("root").ChildNodes)
            {
                if (xn.NodeType != XmlNodeType.Comment)
                    hash.Add(xn.Attributes["name"].Value, xn.InnerText);
            }
            o = hash;
            System.Web.HttpContext.Current.Cache.Insert(path, o);
        }
        else
        {
            o= System.Web.HttpContext.Current.Cache.Get(path);
        }

        //---------------------------------------
        hash = (Hashtable)o;
        if (hash.Contains(key))
        {
            return hash[key].ToString();
        }
        return null;
    }

 

<?xml version="1.0" encoding="UTF-8" ?>
<root>
 <!-- 大章的列表树 -->
 <resource name = "1">一</resource>
 <resource name = "2">二</resource>
 <resource name = "3">三</resource>
 <resource name = "4">四</resource>
 <resource name = "5">五</resource>
 <resource name = "6">六</resource>
 <resource name = "7">七</resource>
 <resource name = "8">八</resource>
 <resource name = "9">九</resource>
 <resource name = "10">十</resource>
 <!-- 顶部菜单 -->
 <resource name = "Login">登陆</resource>
 <resource name = "Logout">退出</resource>
 <resource name = "Register">注册</resource>
 <resource name = "Search">搜索</resource>
 <resource name = "Help">帮助</resource>
        <!-- 大分类菜单 -->
 <resource name = "HomePage">首页</resource>
 <resource name = "ClassRoom">浏览课室</resource>
 <resource name = "Ask">举手发问</resource>
 <resource name = "MyDesk">我的书桌</resource>
 <resource name = "Service">客服中心</resource>

 <resource name = "Welcome">欢迎您</resource>
 <resource name = "ComeIn">欢迎您</resource>
</root>

阅读更多
下一篇在ASP.NET中调用存储过程方法新解
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭