I had previously written, an article explaining Localization and Globalization concept in asp.net 1.3, but with asp.net 2.0 the same generalize concept of localization and globalization can be implemented more easily.
I would suggest reader to read the previous article which help you to identify the ease of applying the concept.
Understanding concept with Example
Step1: Create a Web Project.
Step2: Design your form.
For this example : Take 5 label controls, 4 textbox controls and 1 drop-down list control.
Place the control on form as shown in figure.
Step3: Identifying Resources that needs to be localized (Globalization Phase).
We want the output as shown in figure:
So here Resource that needs localization are
Language Name Label
Long Date Label
Welcome Label (It would be same for all language, except its formatting might change, Note: you can do this easily with style-sheet concept, but as an example here I am explaining it with globalization concept.)
Now, Applying Localization to resources which needs to be localized and globalization phase. (Localization Phase begin).
Step5: Creating Resource File.
For this example i am creating resource file for French and German culture and other culture would get value from default resource file. Right click the Project in Solution Explorer and add a “asp.net folder”
Add App_GlobalResources Folder Add App_LocalResources Folder
Adding Global Resource File under App_GlobalResources Folder
Adding Local Resource File under App_LocalResources Folder
Note: While creating resource file, you should name resource file with filename.aspx.cultercode.resx
1 For Default.aspx file, Default resource file would be Default.aspx.resx
2 For German resource file for Default.aspx would be Default.aspx.de-DE.resx
3 For French resource file for Default.aspx would be Default.aspx.fr-FR.resx
Step6: Adding code in .CS file to make it work
Filling Dropdown with set of languages for user-choice.
Code in Page Load Event.
//Applying Globalization to Header Text
lblWelcome.Text = Resources.GlobalResource.HeaderTitleText; lblWelcome.ForeColor = Color.FromName(Resources.GlobalResource.HeaderTitleColor);
//CultureInfo Class GetCultures gives collection of language.
foreach(CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
//Filling the language collection into drop-downlistbox for user choice.
//Calling the Event when page loads for the first time.
Assigning selected language value to current thread, to reflect changes.
private void ddlLanguage_SelectedIndexChanged(object sender, System.EventArgs e)
Thread.CurrentThread.CurrentUICulture = new CultureInfo(ddlLanguage.SelectedValue);
Thread.CurrentThread.CurrentCulture = new CultureInfo(ddlLanguage.SelectedValue);
Code which requires localization value.
private void ApplyUILocalization()
lblLanguageName.Text = Convert.ToString( this.GetLocalResourceObject("LanguageName"));
lblLongDate.Text = Convert.ToString( this.GetLocalResourceObject("LongDate"));
lblCurrency.Text = Convert.ToString( this.GetLocalResourceObject("Currency"));
lblAmount.Text = Convert.ToString( this.GetLocalResourceObject("Amount"));
Code which does not requires localization.
private void ApplyLocalization()
//Lets Assume currency and amount to keep example simple.
double dblCurrency = 500.50;
double dblAmount = 9580000.75;
//No extra effort for localization as you see here.
txtLanguageName.Text = ddlLanguage.SelectedItem.Text;
txtLongDate.Text = DateTime.Now.ToLongDateString();
txtCurrency.Text = dblCurrency.ToString("c");
txtAmount.Text = dblAmount.ToString("n");
Now, run the application and select the different culture and based on selection you will get the localized display as shown in figure:
When associated resource file not available culture from Default Resource File would be shown.
how simplest syntax structure is used to perform globalization and localization.