Saturday, May 7, 2011

Accessing Culture Information in .NET Application.

When you must access culture information, two key classes of the System.Globalization
namespace that you can use are the CultureInfo and RegionInfo classes.

The CultureInfo Class:
You use the CultureInfo class to convert values to culture-specific formats. The CultureInfo class provides information about cultures including the calendar format, date and time format, sorting rules, numeric formats, currency formats, and the writing system.

For example:

using System;
using System.Globalization;
using System.Threading;
using System.Text;

namespace CurrentCultureinfomod2less1
{
class Program
{
static void Main(string[] args)
{
//1

DateTimeFormatInfo dt1 = new CultureInfo("fr-FR", false).DateTimeFormat;
string s = dt1.GetDayName(DayOfWeek.Monday);
Console.Write(s);

//2


// The following code example shows how to create a CultureInfo for "Spanish - Spain" with the //international sort and another CultureInfo with the traditional sort.

// Creates and initializes the CultureInfo which uses the international sort.
CultureInfo myCIintl = new CultureInfo("it-IT", false);

// Creates and initializes the CultureInfo which uses the traditional sort.
CultureInfo myCItrad = new CultureInfo("en-US", false);

// Displays the properties of each culture.
Console.WriteLine("{0,-33}{1,-25}{2,-25}", "PROPERTY", "INTERNATIONAL", "TRADITIONAL");
Console.WriteLine("{0,-33}{1,-25}{2,-25}", "CompareInfo", myCIintl.CompareInfo, myCItrad.CompareInfo);
Console.WriteLine("{0,-33}{1,-25}{2,-25}", "DisplayName", myCIintl.DisplayName, myCItrad.DisplayName);
Console.WriteLine("{0,-33}{1,-25}{2,-25}", "EnglishName", myCIintl.EnglishName, myCItrad.EnglishName);
Console.WriteLine("{0,-33}{1,-25}{2,-25}", "IsNeutralCulture", myCIintl.IsNeutralCulture, myCItrad.IsNeutralCulture);
Console.WriteLine("{0,-33}{1,-25}{2,-25}", "IsReadOnly", myCIintl.IsReadOnly, myCItrad.IsReadOnly);
Console.WriteLine("{0,-33}{1,-25}{2,-25}", "LCID", myCIintl.LCID, myCItrad.LCID);
Console.WriteLine("{0,-33}{1,-25}{2,-25}", "Name", myCIintl.Name, myCItrad.Name);
Console.WriteLine("{0,-33}{1,-25}{2,-25}", "NativeName", myCIintl.NativeName, myCItrad.NativeName);
Console.WriteLine("{0,-33}{1,-25}{2,-25}", "Parent", myCIintl.Parent, myCItrad.Parent);
Console.WriteLine("{0,-33}{1,-25}{2,-25}", "TextInfo", myCIintl.TextInfo, myCItrad.TextInfo);
Console.WriteLine("{0,-33}{1,-25}{2,-25}", "ThreeLetterISOLanguageName", myCIintl.ThreeLetterISOLanguageName, myCItrad.ThreeLetterISOLanguageName);
Console.WriteLine("{0,-33}{1,-25}{2,-25}", "ThreeLetterWindowsLanguageName", myCIintl.ThreeLetterWindowsLanguageName, myCItrad.ThreeLetterWindowsLanguageName);
Console.WriteLine("{0,-33}{1,-25}{2,-25}", "TwoLetterISOLanguageName", myCIintl.TwoLetterISOLanguageName, myCItrad.TwoLetterISOLanguageName);
Console.WriteLine();


Console.ReadLine();

//The following code examples retrieve a list of all of the available cultures. The code also
//displays the DisplayName property of the current culture in a label.
//Retreiving information about the all cultre

CultureInfo[] cultures =CultureInfo.GetCultures(CultureTypes.AllCultures);
foreach (CultureInfo culture in cultures)
{
Console.WriteLine(culture.Name);
}

}
}
}

No comments:

Recent Posts