简体   繁体   中英

C# CultureInfo.CurrentCulture says en_US but my Windows settings are set to South Africa

I changed my Region/Location in my Windows 8.1 control panel to be South Africa. When I start up my app from Visual Studio 2013 and get the CultureInfo.CurrentUICulture it still says "en-US".

public CultureInfo getCurrentCulture() {
    if (CultureInfo.DefaultThreadCurrentUICulture != null) {
        return CultureInfo.DefaulThreadCurrentUICulture;
    } else {
        return CultureInfo.CurrentUICulture;
    }
}

I've also tried CultureInfo.CurrentCulture instead of CurrentUICulture, but they are behaving the same way. How do I determine what the user's real locale is via code? Or am I setting the region incorrectly via the Windows settings?

My app formats currency strings and such and I need to make sure it is using the correct currency symbols. South Africa is a good use case for me because they still use the English language, but just have different regional number formatting.

I guess I should make this an answer.

Windows distinguishes between the physical location of the user, the desired localization (formatting) properties, and the running language. For instance, a Spanish-speaking user could be located in the UK but want American English formatting. CultureInfo.CurrentCulture refers to the settings under the "Formats" tab of the Regions control panel. (The user interfaces shown in one of the links above are a little out-of-date for Win8; see here for the Win8 analogs.)

This article has a little more information about the various culture properties and how they are set in the user interface: YACVCP (Yet another CurrentCulture vs. CurrentUICulture post)

So, to test South African currency strings and such, you have to change the "Format" drop-down to "English (South Africa)" and rerun.

Also, by experimentation, I have found that Visual Studio 2008 (what I am using) doesn't always pick up the change in locale when I rerun my application. This may be some sort of bug with the Hosting Process . Restarting and rerunning my application usually seems to cure the problem. Closing and re-opening Visual Studio always does.

(Note -- I'm using Win7.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM