You are on page 1of 4

Technical document for Globalization and Localization

Purpose

The purpose of this document is to provide to .NET developers the ability to do


the Globalization and Localization.

Overview

Localization means "process of customizing data and translating resources for a specific
culture", and

Globalization means "process of designing applications that can adapt to different


cultures".

Implementation

For UK Market

You can set the current culture in the following ways:

1. Set the Regional option setting from your control panel


2. Get the culture code from the URL and set that to your current thread as follows:

string UrlHost = this.Context.Request.Url.Host;

if (UrlHost.IndexOf(“.co.uk”, 0, UrlHost.Length) != -1)


{
String cultureCode = "en-GB";
}

CultureInfo currentUICulture =
new CultureInfo(cultureCode);

Thread.CurrentThread.CurrentUICulture = currentUICulture;

Creating the Resource file

If you want resource files for the particular market u can create the file with
naming convention as follows:

<FileName>.en-GB.resx (for ex : ResourceText.en-GB.resx)


When you have set the thread’s CurrentUICulture, ASP.NET automatically selects the
resources that match, in the following order:

1. If a satellite assembly is found with an exactly matching culture, the resources


from that assembly are used.
2. If a satellite assembly is found with a neutral culture that matches the Current-
UICulture, resources from that assembly are used.
3. If a match is not found for the CurrentUICulture, the fallback resources stored in
the executable assembly are used.

Reading from Resource file

You can read the value from the resource files and can assign to your webcontrols.

protected ResourceManager rm =
new ResourceManager("ResourceText",
Assembly.GetExecutingAssembly());

string strTitle = rm.GetString("Title");

Set the currency value :

To set the current culture currency pass the current culture as IFormateprovider to
ToString method.

Convert.ToDouble(“45,000”).ToString("C",
Thread.CurrentThread.CurrentUICulture)

Output :

$45,000.00

Set the DateTime :


To set the current culture date format use “ToShortDateString” method

DateTime dt = new DateTime();


dt = System.DateTime.Now;
dt.ToShortDateString();

Output :

27/03/2006

For German Market


You can set the current culture in the following ways:

1. Set the Regional option setting from your control panel


2. Set the culture code from the URL and set that to your current thread as follows:

string UrlHost = this.Context.Request.Url.Host;

if (UrlHost.IndexOf(“.de”, 0, UrlHost.Length) != -1)


{
String cultureCode = "de-DE";
}

CultureInfo currentUICulture =
new CultureInfo(cultureCode);

Thread.CurrentThread.CurrentUICulture = currentUICulture;

Creating the Resource file

If you want resource files for the particular market u can create the file with
naming convention as follows:

<FileName>.de-DE.resx (for ex : ResourceText.de-DE.resx)

Reading from Resource file

You can read the value from the resource files and can assign to your webcontrols.

protected ResourceManager rm =
new ResourceManager("ResourceText",
Assembly.GetExecutingAssembly());

string strTitle = rm.GetString("Title");

Set the currency value :

To set the current culture currency pass the current culture as IFormateprovider to
ToString method.

Convert.ToDouble(“45,000”).ToString("C",
Thread.CurrentThread.CurrentUICulture)

Output :
4.500€

Set the DateTime :


To set the current culture date format use “ToShortDateString” method

DateTime dt = new DateTime();


dt = System.DateTime.Now;
dt.ToShortDateString();

Output :
27.03.2006

You might also like