By the old United States to sell, work more, wages rose but less, do not finish the work, now finally completed the urgent task at hand, to write about the implementation of the multi-lingual system, our practice is: if the system is simply traditional, directly can be implemented with the function. Because they have one by one correspondence, but what about other languages? Because they do not have the language of the control relationship, can only be written separately. The initial system we use to write a number of pages to achieve, and later think that this method not only a heavy workload, but also to change the function, the same thing to repeat the work. We have used XML records to deal with it later. I do not know how the heroes do it?
Privatevoid Page_Load (object sender, EventArgs e) {if (! Basethis. English.href = "public/login.aspx? Version=eng "; this. Chineset.href = "public/login.aspx? Version=cht "; this. Chineses.href = "public/login.aspx? Version=chs "
The system is made in English by default. If the above selection is Simplified Chinese, it will be judged and loaded with the corresponding language XML
Privatevoid Page_Load (Objectsender, 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 "breakthis.btnlogin.attributes.add ( Onclick" return CheckUser (); "); thisthis
The function Setcontrolstext defined above is to replace the corresponding menu with the language you want.
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); }
The content defined in the XML file is:
?
| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
<?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> |
The results are as follows. This is also true for other pages.
Implementation of multi-lingual systems [GO]