C# CultureInfo.CurrentCulture 说 en_US 但我的 Windows 设置被设置为南非 [英] C# CultureInfo.CurrentCulture says en_US but my Windows settings are set to South Africa

查看:22
本文介绍了C# CultureInfo.CurrentCulture 说 en_US 但我的 Windows 设置被设置为南非的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 8.1 控制面板中将区域/位置更改为南非.当我从 Visual Studio 2013 启动我的应用程序并获取 CultureInfo.CurrentUICulture 时,它​​仍然显示en-US".

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;
    }
}

我也尝试过 CultureInfo.CurrentCulture 而不是 CurrentUICulture,但它们的行为方式相同.如何通过代码确定用户的真实语言环境?还是我通过 Windows 设置错误地设置了区域?

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 区分用户的物理位置、所需的本地化(格式)属性和运行语言.例如,说西班牙语的用户可能位于英国但想要美式英语格式.CultureInfo.CurrentCulture 指的是 "格式" 区域 控制面板.(以上链接之一中显示的用户界面对于 Win8 来说有点过时;请参阅 此处 用于 Win8 类似物.)

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

本文提供了有关各种区域性属性及其在用户界面中设置方式的更多信息:YACVCP(又一个 CurrentCulture 与 CurrentUICulture 帖子)

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.

此外,通过实验,我发现当我重新运行我的应用程序时,Visual Studio 2008(我正在使用的)并不总是能识别区域设置的变化.这可能是 托管进程 的某种错误.重新启动并重新运行我的应用程序通常似乎可以解决问题.关闭并重新打开 Visual Studio 总是如此.

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.

(注意——我使用的是 Win7.)

(Note -- I'm using Win7.)

这篇关于C# CultureInfo.CurrentCulture 说 en_US 但我的 Windows 设置被设置为南非的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆