X hits on this document

139 views

0 shares

0 downloads

0 comments

61 / 67

CUSTOM CULTURES

Two methods, GetNativeRegionName and GetNativeCurrencyName, make an attempt to get the native versions of the region name and currency name, respec- tively. They both work by changing the CurrentCulture to the language for which a native name is required (i.e., Spanish) and then getting the property. If the appro- priate .NET Framework Language Pack is installed, the correct native name will be returned; otherwise, the native name will be the English name and you will need to manually update these values before registering or saving the culture. The GetNa- tiveCurrencyName method is shown here (the GetNativeRegionName is identical, except for the name of the property and the fact that it attempts to get the region’s DisplayName because DisplayName is localized).

protected static string GetNativeCurrencyName( RegionInfo regionInfo, CultureInfo languageCultureInfo) {

string nativeName; CultureInfo oldCultureInfo = Thread.CurrentThread.CurrentUICulture;

try {

// attempt to change the UI culture Thread.CurrentThread.CurrentUICulture = languageCultureInfo; // get the new name (if a corresponding language pack is // installed then this yields a true native name) nativeName = regionInfo.CurrencyNativeName;

} catch (Exception) {

// it was not possible to change the UI culture nativeName = regionInfo.CurrencyNativeName;

} finally {

Thread.CurrentThread.CurrentUICulture = oldCultureInfo;

} return nativeName;

}

Exporting Operating System-Specific Cultures

Another use for custom cultures is to level the playing field of supported cultures across operating systems. Recall that the list of available cultures in the .NET Frame- work 2.0 is determined by the operating system upon which the code is running.

37

Document info
Document views139
Page views139
Page last viewedSat Dec 03 20:39:14 UTC 2016
Pages67
Paragraphs859
Words13458

Comments