Monday, May 19, 2008

.Net Globalization

Globalization is the process of designing and developing applications that function for multiple cultures.

Lets begin our discussion on .Net Globalization with an ASP .Net example. Start an asp. Net project. Go to web.config and type the following:






Place a Calendar control on the form. When you run the application you will see an Arabic calendar with the Hijri year.


















Displaying All Cultures

Here I am creating an array of CultureInfo class. CultureInfo class contains information about a culture like its name, Calendar, Day Names, Month Names, Currency Format, etc.

SpecificCulture is a culture type where there is language code as well as country code. Examples are ar-SA, ml-IN, fr-FR. Here the first portion represents the Language Code and the second portion represents the Country Code.
using System.Globalization;

private void Form1_Load(object sender, EventArgs e)
{
CultureInfo[] cis = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
foreach (CultureInfo ci in cis)
listBox1.Items.Add(String.Format( ci.ToString()));
}

Displaying DisplayName and NativeName and Day Names of a Selected Culture

























using System.Globalization;
private void Form1_Load(object sender, EventArgs e)
{
CultureInfo[] cis = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
foreach (CultureInfo ci in cis)
comboBox1.Items.Add(String.Format( ci.ToString()));
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
lstDetails.Items.Clear();
CultureInfo ci = new CultureInfo(comboBox1.Text);
lstDetails.Items.Add(ci.DisplayName.ToString());
lstDetails.Items.Add(ci.NativeName.ToString());
lstDetails.Items.Add("");
lstDetails.Items.Add("Day names");
string[] strDayNames = ci.DateTimeFormat.DayNames;
foreach (string strDay in strDayNames)
lstDetails.Items.Add(strDay);

lstDetails.Items.Add("");
lstDetails.Items.Add("Month Names");
string[] strMonthNames = ci.DateTimeFormat.MonthNames;
foreach(string strMonth in strMonthNames)
lstDetails.Items.Add(strMonth);
}



Related Blog
Globalization in Windows Forms - Application with multi language support


Happy Programming
shalvin.com

1 comment: