Describe how to implement globalization and localization in the use interface in .NET
Application use locale to identify the language and country of the user. E.g.: for English speaking US based user it would be “en-US”. The locale also has the information for datetime, currency etc formats. To write an application in such a way that its cultural and language neutral is globalization. Localization is to make the application specific to the end user’s culture and language. We need to identify all the resources that would be affected and keep them in different resource files.
Implementing Globalization:1. System.Globalization namespace is used.
2. Create a new web application.
3. Drag 2 label controls, a dropdownlist and a button control. Add 2 items to the drop down, en-US and fr-FR.
4. Add a new folder called resources and add 2 resource assembly files in it.
Example: res1.resx and res1.fr-FR.resx In res1.resx, add a key “Welcome” and value as “Hello there”. In res1.fr-FR.resx, add a key called “Welcome” and value as “Bon Journe”.
5. Generate their resource files by using the resgen command for each of these resource files and keep them in the App_GlobalResources folder.
6. On button’s click even at the following code:
Session["language"]=dropdownlist1.SelectedItem .Text ;
Response.Redirect ("Webform2.aspx");
7. Add a label inWebform2.aspx. In page load event of Webform2.aspx.cs add the following code.
System.Resources.ResourceManager resourceManager = ResourceManager.CreateFileBasedResourceManager("res1",Server.MapPath
("Resources")+Path.DirectorySeparatorChar , null);
string getLanguage = Session["language"].ToString ();
CultureInfo cultureInfo=new CultureInfo(getLanguage);
Label1.Text=resourceManager.GetString ("Welcome",cultureInfo);
When you execute the Webform1.aspx, choose one of the English or French option from the dropdownlist and hit the button. It should display welcome message based on the chosen option from the dropdownlist.