zoukankan      html  css  js  c++  java
  • 多语言系统的实现

    被老美卖掉后, 工作多了,工资涨得却少了,做不完的活, 现总算完成了手头上的紧急工作,上来写一下有关多语言系统的实现, 我们的做法是:如果系统只是简繁体,直接就可以用函数实现了. 因为他们具有一一对应关系,可是其它语言呢? 由于不具有语言的对照关系,只能分别写了. 最初的系统我们是采用写多个页面来实现,后面觉得这种方法不但工作量大,而且改功能的话,同一事情要重复劳动.后面我们就采用XML记录的方式来处理了. 不知各位大侠是如何做的呢?

     private void Page_Load(object sender, EventArgs e)
            {
                if (!base.IsPostBack)
                {
                    this.English.HRef = "public/login.aspx?Version=eng";
                    this.ChineseT.HRef = "public/login.aspx?Version=cht";
                    this.ChineseS.HRef = "public/login.aspx?Version=chs";
                   
                }
            }

    系统默认做成的是英文的. 如果上面选择是简体中文,则会判断,并加载相应语言的XML

     private void Page_Load(object sender, EventArgs e)
            {
                this.lblMsg.Text = "";
                this.lblError.Text = "";
                if (!this.Page.IsPostBack)
                {
                    if (base.Request.QueryString.Get("Version") != null)
                    {
                        this.Session["Version"] = base.Request.QueryString.Get("Version");
                    }
                    else
                    {
                        this.Session["Version"] = "chs";
                    }
                    if (this.Context.User.Identity.IsAuthenticated)
                    {
                        base.Response.Redirect("../mainform.aspx");
                    }
                    switch (this.Session["Version"].ToString())
                    {
                        case "chs":
                            base.SetControlsText(base.Server.MapPath("login_chs.xml"));
                            break;
    
                        case "cht":
                            base.SetControlsText(base.Server.MapPath("login_cht.xml"));
                            break;
                    }
                    this.btnLogin.Attributes.Add("onclick", "return checkuser();");
                    this.AddAdmin();
                }
                this.CheckUser();
            }

    上面的函数SetControlsText定义, 就是把相应的菜单替换成你想要的语言.

     protected void SetControlsText(string Filename)
            {
                XmlDocument document = new XmlDocument();
                document.Load(Filename);
                XmlNode node = document.SelectSingleNode("/Controls");
                this.SetLabelText(node);
                this.SetButtonText(node);
                this.SetCheckBoxText(node);
                this.SetRadioButtonText(node);
                this.SetRadioButtonListText(node);
                this.SetDataGridHeaderText(node);
                this.SetCusDataGridHeaderText(node);
            }

     xml文件里定义的内容是:

    <?xml version="1.0" encoding="gb2312"?> 
    <Controls>
    <Labels>
     <Label>
      <id>User</id>
      <name>用户</name>
     </Label>
     <Label>
      <id>Password</id>
      <name>密码</name>
     </Label>
     <Label>
      <id>Forget your password?</id>
      <name>忘记密码了吗?</name>
     </Label>
     <Label>
      <id>Login</id>
      <name>登录</name>
     </Label>
    </Labels>
    
    <Buttons>
     <Button>
      <id>Login</id>
      <name>登录</name>
     </Button>
     <Button>
      <id>Home</id>
      <name>首页</name>
     </Button>
     <Button>
      <id>Email password</id>
      <name>发送密码到邮箱</name>
     </Button>
       <Button>
      <id>Send Mail to me</id>
      <name>发送密码到邮箱</name>
     </Button>
    </Buttons>
    <CheckBoxs>
     <CheckBox>
      <id>Login automatically</id>
      <name>自动登录</name>
     </CheckBox>
    </CheckBoxs>
    </Controls>
    

      

    结果如上图. 其它页面亦如此.

     

  • 相关阅读:
    linux设备驱动模型二【转】
    Linux设备驱动模型【转】
    内核学习方法,编译、调试等常见问题【转】
    第十四章 netlink机制--基于Linux3.10【转】
    手把手教你把Vim改装成一个IDE编程环境(图文)【转】
    Netlink通信机制【转】
    mac电脑的使用
    【转】不要使用SBJSON(json-framework)
    【转】IOS中Json解析的四种方法
    【转】iOS程序自动检测更新的实现 -- 思路不错
  • 原文地址:https://www.cnblogs.com/Geton/p/3899293.html
Copyright © 2011-2022 走看看