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

▼魔方 西西 提交于 2019-12-24 00:48:29

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/25251224/c-sharp-cultureinfo-currentculture-says-en-us-but-my-windows-settings-are-set-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!