Double-click on the Resource.resx file and populate it with content, as shown in Figure 11.
Figure 11. Populating the Resource.resx file
Duplicate a copy of the Resource.resx file and name it Resource.zh-CN.resx. As usual populate its contents, as shown in Figure 12.
Figure 12. Populating the Resource.zh-CN.resx file
Both the Resource.resx and Resource.zh-CN.resx files
contain the resources for the English and Chinese cultures. In the
event, you use the
Resources class to access the resources defined
in these two resource files, as follows:
Protected Sub Page_PreInit( _ ByVal sender As Object, ByVal e As System.EventArgs) _ Handles Me.PreInit Dim lang As System.Globalization.CultureInfo lang = New System.Globalization.CultureInfo("zh-CN") System.Threading.Thread.CurrentThread.CurrentCulture = lang System.Threading.Thread.CurrentThread.CurrentUICulture = lang lblName.Text = Resources.Resource.lblName lblBirthday.Text = Resources.Resource.lblBirthday lblAddress.Text = Resources.Resource.lblAddress lblSalary.Text = Resources.Resource.lblSalary End Sub
F5 to test the application. Your page should now display in Chinese, regardless of the language preference setting in IE (see Figure 13).
Figure 13. Displaying the page in Chinese
Localizing your web applications has been simplified in ASP.NET 2.0. If you are targeting your application to international users, it is important that you take the extra effort to ensure that your application is world-ready. Fortunately, ASP.NET 2.0 makes it really easy for you.
Wei-Meng Lee (Microsoft MVP) http://weimenglee.blogspot.com is a technologist and founder of Developer Learning Solutions http://www.developerlearningsolutions.com, a technology company specializing in hands-on training on the latest Microsoft technologies.
Return to OnDotNet.com
Showing messages 1 through 6 of 6.
2008-03-11 13:02:07 dotnetJr [View]
How to Populating the Resource.zh-CN.resx file
2008-02-19 04:53:18 email@example.com [View]
Globalization and Localization
2007-08-09 15:47:47 jinksk [View]
using the page preinit method
2007-07-22 21:12:04 Salvatore [View]
Error Message Issue
2006-01-05 02:23:11 YKR [View]
Downsides to using Resource Files?
2005-08-24 11:15:34 laithz [View]