X hits on this document

145 views

0 shares

0 downloads

0 comments

42 / 67

18

.NET INTERNATIONALIZATION

Custom Culture Parents and Children

As you know, there is a hierarchy to CultureInfo objects in which specific cultures (e.g., “en-US”) fall back to neutral cultures (e.g., “en”), which fall back to the invari- ant culture. This hierarchy manifests itself through the CultureInfo.Parent prop- erty. Custom cultures fit into this hierarchy, but they are not restricted to the existing pattern of just three levels of cultures, nor that specific cultures have parent neutral cultures. Let’s look at two examples. The first is a hierarchy of en-GB custom cultures in which the Parent property is not explicitly set in code and is left in the hands of the LoadDataFromCultureInfo method:

BuildCulture(“English (United Kingdom) Acme”

,

“en-GB-Acme”

,

“en-GB”);

BuildCulture(“English (United Kingdom) Acme Child” “en-GB-Acme-Child” , “en-GB-Acme”);

,

BuildCulture(“English (United Kingdom) Acme Grandchild”, “en-GB-Acme-GrandC”, “en-GB-Acme-Child”);

private void BuildCulture(string englishName, string cultureName, string loadFromCultureName) {

CultureInfo cultureInfo = new CultureInfo(loadFromCultureName);

RegionInfo regionInfo = new RegionInfo(cultureInfo.Name);

CultureAndRegionInfoBuilder builder = new CultureAndRegionInfoBuilder(cultureName, CultureAndRegionModifiers.None);

// add data from the culture builder.LoadDataFromCultureInfo(cultureInfo); // add data from the region builder.LoadDataFromRegionInfo(regionInfo); // set the culture’s English name builder.CultureEnglishName = englishName;

builder.Register();

}

Document info
Document views145
Page views145
Page last viewedSun Dec 04 18:45:00 UTC 2016
Pages67
Paragraphs859
Words13458

Comments