Posts filed under ‘Globalization’

Build custom culture for globalization

In globalization we need to use culture of different regions, there may be possibility when we required, having mix of more than one culture, at that time this custom culture can be very useful.

àCreate an instance of  CultureAndRegionInfoBuilder class. This class can be available by adding reference to System.Globalization namespace in our application.

Give your name to custom culture, here we have “en-PC”

CultureAndRegionInfoBuilder cusBuild =

new CultureAndRegionInfoBuilder(“en-PC”, CultureAndRegionModifiers.None);

à Load data from existing culture, we can use any of the available culture. Here we have used “en-GB” its indicates culture of Great Brittan.

cusBuild.LoadDataFromCultureInfo(new CultureInfo(“en-GB”));

à set the new CultureAndRegionInfoBuilder object with region information

cusBuild.LoadDataFromRegionInfo(New RegionInfo(“GB”))

à Set culture specific settings.

cib.CultureEnglishName = “Pin Culture”

cib.CultureNativeName = “Pecer Culture”

cib.IsMetric = True

cib.ISOCurrencySymbol = “PC”

cib.RegionEnglishName = “Pig Latin Region”

cib.RegionNativeName = “Pecrer Region Culture”

à ‘ Register the custom culture

cusBuild.Register()

One thing should be note down when creating custom culture; we should register it when we complete it. To register culture we should have administrator privileges, so it should be done at the setup process.

Once we have successfully registered our culture, we can use it as other culture like

‘ Display some of the properties of the custom culture.

Dim ci As CultureInfo = New CultureInfo(“en-PC”)

We can access all properties of it as.

Console.WriteLine(“Name: . . . . . . . . . . . . . {0}”, ci.Name);

Console.WriteLine(“EnglishName:. . . . . . . . . . {0}”, ci.EnglishName);

Console.WriteLine(“NativeName: . . . . . . . . . . {0}”, ci.NativeName);

April 29, 2010 at 4:26 am Leave a comment

Why should Globalization?

Globalization means we need to build application that work anywhere with respective culture of particular region. It should show region specific date time format, currency symbol, language etc.

Thanks to .net framework, they have provided System.Threading and System.Globalization namespaces to build application that supports Globalization.

As we know different countries have their own language and have their own data format facility. Say for example some countries use comma separator for decimal some use period. If we have hard coded application that certainly it will not work in different culture than we have built.

Culture is always specified in computer when application run on it, it takes culture from computer previously set culture. We can override this culture but it can be only for application. To set culture we can use below syntax.

Thread.CurrentThread.CurrentCulture = new CultureInfo(“es-ES”);

Here we have provided culture information by “en-ES”. There are different types of culture are available like specific culture, natural culture. Specific culture gives all of the data format facility for that culture while in case of natural culture we get only language specific transformation.

By providing culture setting we can also change its date,time format or even we can change currency format by accessing various property of date time and data format classes of NumberFormat and NumberDecimalSeparator.

One care should be taken when we use globalization in sorting and comparison, because in different culture they have different priority of letters and symbol priority.

At that time we can have two options either use StringCompariosn.InvarianCulture or use below syntax.

Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture

April 28, 2010 at 4:47 am Leave a comment


Archives

Categories

May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Blog Stats

  • 8,361