关闭

多语言版本的测试

606人阅读 评论(0) 收藏 举报

    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>

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:9427次
    • 积分:164
    • 等级:
    • 排名:千里之外
    • 原创:6篇
    • 转载:3篇
    • 译文:0篇
    • 评论:1条
    文章分类
    文章存档
    最新评论