Requirements: Our ASP.NET site needs to provide multi-language support. Considering that we are using ASP.NET2.0, we can use resource files to achieve this.
NOTE: Here we use programming method to achieve, for other methods, please see:
http://msdn2.microsoft.com/en-us/library/c6zyy3s9.aspx
Next we demonstrate a simple example
Steps:
Step1: Create an ASP.NET site in Visual Studio2005
Step2: Add App_GlobalResources to the website project
Note: Here we use global resource files as a demonstration. The steps for local resource files are similar. Regarding the similarities and differences between global resource files and local resource files, please See
the section Choosing Between Global and Local Resource Files in
http://msdn2.microsoft.com/en-us/library/ms227427.aspx.
Step 3: Add an item to App_GlobalResources, select the Resource File template, and name it Site.resx
Note : This is our default language resource file, and
the key/value pairing of this resource file must be written:
Name : btnSubmitText
Value: Submit
Step4: Add the resource files in various languages we need. Here we add two files
Site.zh-CN.resx
and write in the key/value pairing of this resource file:
Name: btnSubmitText
Value: Confirm
Site.en-US .resx
writes in the key/value pair of this resource file:
Name : btnSubmitText
Value: Submit
Note: When naming the resource file here, you need to follow the following format:
[Class]. [Culture Name].resx,
for example, Site.zh-CN.resx.
For Culture Name, please refer to the Remarks section of the CultureInfo class in MSDN.
Step5: Add a Button control to our Default page with the ID btnSubmit
Step6: Add two Button controls to our Default page with the IDs btnChinese and btnEnglish. Text is Chinese. English
is added in the Click event method of btnChinese. Code:
Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CN");
btnSubmit.Text = Resources.Site.btnSubmitText;
In the Click event method of btnEnglish, add the code:
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
btnSubmit.Text = Resources.Site.btnSubmitText;
Note: If we do not specify the CurrentUICulture of the current thread in the code, the program will judge based on the settings in the browser. You can make the default settings in the language settings in IE.
OK, we are ready to run.
Let everyone do UAT, haha. As expected, everything worked as we expected.
By the way, the few articles published recently are not very difficult. In fact, the important thing is to tell everyone an alternative method, or some knowledge points that everyone does not pay much attention to, and guide everyone to continue to explore if necessary. I will briefly introduce the content in MSDN or give direct links, so that the article will not appear to be huge and bloated, and let everyone focus on certain points. Enjoy it J
PS: Everyone is welcome to join me on MSN or QQ to discuss .NET 2.0 (mainly C# 2.0 and ASP.NET 2.0) and .NET 3.0. I found that few people in the several QQ groups I have joined discuss these two topics. version of the content. There are also many questions that some friends have asked me. In fact, you can find answers and examples by searching MSDN, so my suggestion is to first find solutions by searching for information yourself. There are also some friends who directly ask me for the source code, or ask me to make a demonstration project that already has code in the MSDN examples. My suggestion is that you should try it yourself first. I will prepare it for you, and then you can It’s definitely not as effective as doing it yourself.
http://www.cnblogs.com/wdxinren/archive/2006/09/07/497686.html