从.NET应用程序的角度来看,CurrentUICulture设置在Windows 7中的哪个位置? [英] Where does CurrentUICulture setting reside in Windows 7 from a .NET app perspective?
问题描述
我想测试我的应用在不同文化下的工作方式.
因此,出于测试目的,在Windows 7下,我尝试更改系统设置中的CurrentUICulture
.
I would like to test how my app would work under different cultures.
So for testing purposes, under Windows 7, I tried to change CurrentUICulture
in system settings.
这似乎是正确的选择:Language for non-Unicode programs
如此处建议,但它不起作用,即应用的语言环境仍为英语.
This seems to be the right option: Language for non-Unicode programs
as suggested here, but it does not work, i.e. app's locale is still English.
我也在Region and Language
对话框中尝试过此操作:
I also tried this in Region and Language
dialog:
- 格式:将格式更改为另一种文化
- 位置:将当前位置设置为另一个国家/地区.
问题是我应该在Windows 7中设置什么才能影响它:
The question is what should I set in Windows 7 for it to affect:
Thread.CurrentThread.CurrentUICulture
不用写这个:
Thread.CurrentThread.CurrentUICulture = New CultureInfo("fr")
最终,此代码应选择正确的区域性,获取正确后缀的资源文件,并将其显示在屏幕上(使用上面的代码行):
Ultimately, this code should pick the correct culture, get the correctly suffixed resource file and display it on the screen (which it does with the above line in place):
Label1.Text = My.Resources.Form1Resource.TestString
在StackOverflow上也提出了类似的问题,但没有一个答案解决了这个问题.
A similar question has been asked on StackOverflow, but none of the answers addressed this issue.
推荐答案
旋钮位于区域和语言"控制面板的键盘和语言"选项卡上.点击安装/卸载语言…"按钮开始.如果仅安装了一种UI语言,则需要安装另一种.向导将引导您完成此过程.您还必须注销并重新登录才能看到效果.
The knob is on the "Keyboard and Languages" tab of the "Region and Language" control panel. Click on the "Install/uninstall languages…" button to get started. If you only have one UI language installed, you will need to install another one. The wizard should walk you through this. You will also have to log off and log back on in order to see the effect.
在大多数情况下,CurrentUICulture
属性将返回用户首选的UI语言列表中的第一种语言,因此进行设置就足够了.其他语言将用作备用语言,以防无法使用首选语言获得必要的资源.
In most cases, the CurrentUICulture
property is going to return the first language in the list of user preferred UI languages, so setting this should be sufficient. The other languages are used as fallback languages in case necessary resources are not available in the preferred language.
但是CurrentUICulture
用于确定UI文化的实际算法要复杂一些:
But the actual algorithm that CurrentUICulture
uses to determine the UI culture is a bit more complicated:
- 首先,它检查
DefaultThreadCurrentUICulture
属性.如果不是null
,它将返回设置为当前应用程序域中所有线程的默认UI文化的任何内容. - 如果
DefaultThreadCurrentUICulture
是null
,它将调用GetUserDefaultUILanguage
一个>功能.- 该函数会检查当前用户是否设置了首选的UI语言,就像我在开始时所描述的那样.如果是这样,它将返回该语言.
- 如果用户尚未设置UI语言,则该函数返回为系统设置的UI语言.这是由管理员在区域和语言"控制面板的高级"选项卡中完成的,并且需要重新启动才能生效.
- 如果没有为系统设置首选语言,则使用系统 default UI语言.这是Windows本地化版本(XP和更早版本)的语言,或者是在安装过程中选择的语言(Vista和更高版本).
- First, it checks the
DefaultThreadCurrentUICulture
property. If that is notnull
, it returns whatever UI culture has been set as the default for all threads in the current application domain. - If
DefaultThreadCurrentUICulture
isnull
, it calls theGetUserDefaultUILanguage
function.- That function checks to see if the current user has set a preferred UI language, just like I described at the beginning. If so, it returns that language.
- If the user has not set a UI language, the function returns the UI language that is set for the system. This is done by the administrator in the "Advanced" tab of the "Region and Language" control panel and requires a reboot in order to take effect.
- If there is no preferred language set for the system, then the system default UI language is used. This is either the language of the localized version of Windows (XP and earlier), or the language that was selected during installation (Vista and later).
当然,这种测试方法可能有点过大,因为它正在更改 global 设置(至少对于整个用户帐户而言).由于当前的UI文化是每个线程,因此您可以仅针对应用程序的线程对其进行修改.为此,请设置
Thread.CurrentUICulture
属性.如果您的应用程序是多线程的,则可能需要设置DefaultThreadCurrentUICulture
属性,以确保其他线程采用正确的区域性.问题是您已经找到了,但是我不清楚您为什么不想使用它.Of course, this method of testing might be a little overkill because it's changing global settings (at least, for your entire user account). Because the current UI culture is maintained per-thread, you can modify it just for your application's thread. To do this, set the
Thread.CurrentUICulture
property. If your application is multi-threaded, you might want to set theDefaultThreadCurrentUICulture
property to ensure that additional threads pick up the correct culture. The question says that you already found this, but I'm not clear on why you don't want to use it.另外,在将UI语言与语言环境混淆时要小心;它们不一样.
CurrentCulture
是区域设置,用于设置日期/数字/时间格式和排序顺序等内容.CurrentUICulture
是UI语言,用于加载正确本地化的资源.它们可能是相同的,我想它们经常是 ,但不一定必须如此.在某些情况下,用户可能希望他们与众不同;例如,如果他们说英语,并且喜欢本地化的英语版本,但想查看按照其习惯格式化的日期和时间之类的内容.Also, be careful about confusing the UI language with the locale; they are not the same.
CurrentCulture
is the locale, which sets things like date/number/time formats and the sort order.CurrentUICulture
is the UI language, which deals with loading the correctly localized resources. They might be the same, and I suppose they often are, but they do not have to be. There are cases where a user might want them to be different; for example, if they speak English and prefer the localized English version, but want to see things like dates and times formatted according to their custom.这篇关于从.NET应用程序的角度来看,CurrentUICulture设置在Windows 7中的哪个位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!