WindowsDevCenter.com
oreilly.comSafari Books Online.Conferences.

advertisement


AddThis Social Bookmark Button

Localization in ASP.NET 2.0
Pages: 1, 2, 3, 4

Double-click on the Resource.resx file and populate it with content, as shown in Figure 11.



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
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 Page_PreInit 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

Press 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
Figure 13. Displaying the page in Chinese

Summary

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