Asp.net globalization tutorial


Asp.net globalization tutorial - contributed by Nihal Singh

.NET Tutorial > Globalization

Globalization

In general we develop our application in US culture (English Language) but what if we want to sell our software where English language is not used.
Globalization is the process of designing and developing applications that supports for multiple cultures. So a program or an application can be usable across multiple cultures and regions, no matter which language or culture is there. All the types are available in System. Globalization namespace

CultureInfo Class

This class enables you to get the culture information of a .NET application. You can retrieve and manipulate the culture information by using this class. This class mainly provides the information such as:

  • Format of numbers and dates
  • Casing conventions
  • Culture’s writing system
  • Culture’s calendar
  • Culture’s language

Culture can be divided in three Categories:

  • Invariant Culture
  • Neutral Culture
  • Specific Culture

Invariant Culture

This culture category is culture-insensitive. You can use this culture when you using dates or strings regardless of the culture’s format. It will greatly simplify the task of comparing these dates or Strings.

Neutral Culture

A neutral culture is represented with a language but has no relationship to countries or regions.
The neutral culture will be designated by the first two characters As example:

English (en) Neutral Culture
French (fr)
Spanish (sp)


Specific Culture

It represented by a neutral culture, a hyphen, and then a specific culture abbreviation. For example, in the following designations “fr-FR” , “en-US”, and “zh-CN” fr , en and zh represent the neutral culture (French , English and Chinese, respectively), and FR , US and CN represent the specific culture (France , United States and China, respectively).

Example:

This example gives the culture information of current application.

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


protected void Page_Load(object sender, EventArgs e)
{

            CultureInfo ci = Thread.CurrentThread.CurrentCulture;

            Label1.Text="Display Name :" + ci.DisplayName +"<br>" +
            "EnglishName :" + ci.EnglishName + "<br>" +
            "IsNeutralCulture :" + ci.IsNeutralCulture + "<br>" +
            "Name :" + ci.Name + "<br>" +
            "NativeName :" + ci.NativeName + "<br>" +
            "TwoLetterISOLanguageName :" + ci.TwoLetterISOLanguageName;

}

OUTPUT:

Display Name : English(United States)
English Name: English(United States)
IsNeutralCulture: False
Name: en-US
NativeName : English(United States)
TwoLetterISOLanguageName: en 

DateTimeFormatInfo and NumberFormatInfo Classes

The DateTimeFormatInfo and NumberFormatInfo class provides important set of methods and properties to handle and respond to the dates of different cultures

Example:

The following example gives the name of days in French.

protected void Page_Load(object sender, EventArgs e)
{

            CultureInfo demo = new CultureInfo("fr-FR");
            String[] Days = demo.DateTimeFormat.DayNames;
            foreach (String Day in Days)
            {
                        Label1.Text += Day+"<br>";
            }
}

Example:

The following example gives the currency symbol in French.

protected void Page_Load(object sender, EventArgs e)
{

CultureInfo UsersCulture = new CultureInfo("fr-FR");

Response.Write("French Currency Symbol : "
+ UsersCulture.NumberFormat.CurrencySymbol + "<br>" + "Number Decimal Symbol: "
+ UsersCulture.NumberFormat.NumberDecimalSeparator);

}

OUTPUT

French Currency Symbol:
Number Decimal Symbol: ,

RegionInfo Class

RegionInfo class provides specific information about a particular country or region.RegionInfo class constructor uses the numeric identifiers (such as LCID). We can get the region name and currency symbol of the user’s region by writing the following code.

protected void Page_Load(object sender, EventArgs e)
{

            CultureInfo MyCulture = Thread.CurrentThread.CurrentCulture;
            RegionInfo MyRegion = new RegionInfo(MyCulture.LCID);
            Response.Write("English Name : " + MyRegion.EnglishName +"<br>"+
                                    "Display Name : " + MyRegion.DisplayName +"<br>"+
                                    "Currency Symbol : " + MyRegion.CurrencySymbol +"<br>"+ 
                                    "Name : " + MyRegion.Name);

}

Output:

English Name: United States
Display Name: United States
Currency symbol: $
Name: US



Write your comment - Share Knowledge and Experience



 
Latest MCQs
» General awareness - Banking » ASP.NET » PL/SQL » Mechanical Engineering
» IAS Prelims GS » Java » Programming Language » Electrical Engineering
» English » C++ » Software Engineering » Electronic Engineering
» Quantitative Aptitude » Oracle » English » Finance
Home | About us | Sitemap | Contact us | We are hiring