this blog contains information for .net and sql stuffs. You can find various tips and tricks to overcome problem you may be facing in ...

Thursday, April 29, 2010

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);

No comments: