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. 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 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. 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
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 6 of 6.
-
contact form
2008-03-11 13:02:07 dotnetJr [Reply | View]
Nice article!!! how to change the key boad words when we fill the contact form? ex: contact form is in French: letter to be enterd should be in french , if it is chinees then we can fill the form in chineese, etc:
-
How to Populating the Resource.zh-CN.resx file
2008-02-19 04:53:18 wah898@hotmail.com [Reply | View]
How do you Populating the Resource.zh-CN.resx file
using chinese character?
Are you actually type in UniCode?
-
Globalization and Localization
2007-08-09 15:47:47 jinksk [Reply | View]
Why would my website only be using the *.aspx.resx localization files and not use the *aspx.es.resx files even when I set the globalization in the web.config file and check the Thread's current culture and it is indeed being set to "es-PR"
-
using the page preinit method
2007-07-22 21:12:04 Salvatore [Reply | View]
There is actually no need to set the culture in page preinit method and then later run through the associated acrobatics to manually set individual control properties. There is a method of the page class InitializeCulture() where you can put the culture initialization code. Putting your code there will cause the page to pull the localized resources from the appropriate resource file (as opposed to the default resource file which is (initially) happening here). Also for more info on localization there is an article in the msdn library see -- .NET Development/Web Applications (ASP.NET)/Technical Articles/ASP.NET 2.0/ASP. NET 2.0 Localization....
-
Error Message Issue
2006-01-05 02:23:11 YKR [Reply | View]
Hi,
Thanks for very good article.
Here I have One doubt regarding Error Messages
Display text in the web pages will be changed accroding to the Culutures. If we are doing some client side validation and displaying Error Messages. In this case is there any way of doing these messages also according to the culutures.
Regards,
YKR
-
Downsides to using Resource Files?
2005-08-24 11:15:34 laithz [Reply | View]
First of all, Thank you for this great article.
I was wondering if there are any downsides to using resource files extensively. Here is my scenario:
I am developing a bi-lingual web application which is expected to handle alot of traffic (millions of page views per month). It will have around 10 different asp.net pages, each having two resource files. The resource files will contain a reasonable amount of text.
It seems to me that since resource files are basically XML files, this will pose alot of load on the server because it has to parse the xml every time.
Is this normal or are there any special practices I should be aware of when using resource files?
Thank you.





