X hits on this document

143 views

0 shares

0 downloads

0 comments

41 / 67

CUSTOM CULTURES

following code results in an ArgumentException (“Culture ID 4096 (0x1000) is not a supported culture”):

CultureInfo cultureInfo1 = new CultureInfo(4096);

This is one of the reasons why you should treat LCIDs as a legacy feature or for use with Win32 APIs. You should also conclude from this that if you store the iden- tities of cultures in a database or configuration file, your method should always be capable of storing the culture name instead of the culture LCID for custom cultures. Recall from the “Alternate Sort Orders” section of Chapter 6 that the .NET Frame- work 2.0 supports the creation of cultures with alternate sort orders using string identifiers (e.g., “es-ES_tradnl”) in addition to LCIDs; it should be apparent that, when using the .NET Framework 2.0, you should always store culture identifiers using strings, not integers. If you want to enforce this in your applications, look at the “CultureInfo must not be constructed from LCID” and “RegionInfo must not be constructed from LCID” FxCop rules in Chapter 13, “Testing Internationalization Using FxCop.”

Before we leave the subject of alternate sort orders, it is worth pointing out that because the custom culture mechanism is based upon culture names and not culture LCIDs, it is not possible to create replacement custom cultures for a culture with an alternate sort order. However, you can create a “supplemental substitute” custom culture for an alternate sort order:

// create the es-ES culture with the Traditional sort order CultureInfo cultureInfo = new CultureInfo(“es-ES-Tradnl”); RegionInfo regionInfo = new RegionInfo(cultureInfo.Name);

CultureAndRegionInfoBuilder builder = new CultureAndRegionInfoBuilder(“es-ES-Tradnl-Acme”, CultureAndRegionModifiers.None);

// load in the data from the existing culture and region builder.LoadDataFromCultureInfo(cultureInfo); builder.LoadDataFromRegionInfo(regionInfo);

// make custom changes to the culture ... ...

builder.Register();

17

Document info
Document views143
Page views143
Page last viewedSun Dec 04 02:34:05 UTC 2016
Pages67
Paragraphs859
Words13458

Comments