vb.net 从 .NET 应用程序的角度来看,CurrentUICulture 设置在 Windows 7 中的什么位置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17052214/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where does CurrentUICulture setting reside in Windows 7 from a .NET app perspective?
提问by Neolisk
I would like to test how my app would work under different cultures.
So for testing purposes, under Windows 7, I tried to change CurrentUICulturein system settings.
我想测试我的应用程序在不同文化下的工作方式。因此,出于测试目的,在 Windows 7 下,我尝试更改CurrentUICulture系统设置。
This seems to be the right option: Language for non-Unicode programsas suggested here, but it does not work, i.e. app's locale is still English.
这似乎是正确的选择:Language for non-Unicode programs正如这里所建议的,但它不起作用,即应用程序的语言环境仍然是英语。
I also tried this in Region and Languagedialog:
我也在Region and Language对话框中尝试过这个:
- Formats: change Format to another culture
- Location: set current location to another country.
- 格式:将格式更改为另一种文化
- 位置:将当前位置设置为另一个国家。
The question is what should I set in Windows 7 for it to affect:
问题是我应该在 Windows 7 中设置什么才能影响:
Thread.CurrentThread.CurrentUICulture
instead of having to write this:
而不是必须写这个:
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
A similar question has been asked on StackOverflow, but none of the answers addressed this issue.
在 StackOverflow 上也有人问过类似的问题,但没有一个答案解决了这个问题。
回答by Cody Gray
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.
该旋钮位于“区域和语言”控制面板的“键盘和语言”选项卡上。单击“安装/卸载语言...”按钮开始。如果您只安装了一种 UI 语言,则需要安装另一种语言。向导应该会引导您完成此操作。您还必须注销并重新登录才能看到效果。
In most cases, the CurrentUICultureproperty 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 CurrentUICultureuses to determine the UI culture is a bit more complicated:
但是CurrentUICulture用于确定 UI 文化的实际算法要复杂一些:
- First, it checks the
DefaultThreadCurrentUICultureproperty. If that is notnull, it returns whatever UI culture has been set as the default for all threads in the current application domain. - If
DefaultThreadCurrentUICultureisnull, it calls theGetUserDefaultUILanguagefunction.- 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 defaultUI 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).
- 首先,它检查
DefaultThreadCurrentUICulture属性。如果不是null,它返回任何 UI 文化已设置为当前应用程序域中所有线程的默认值。 - 如果
DefaultThreadCurrentUICulture是null,则调用该GetUserDefaultUILanguage函数。- 该函数会检查当前用户是否设置了首选 UI 语言,就像我在开头所描述的那样。如果是,则返回该语言。
- 如果用户尚未设置 UI 语言,则该函数返回为系统设置的 UI 语言。这是由管理员在“区域和语言”控制面板的“高级”选项卡中完成的,需要重新启动才能生效。
- 如果没有为系统设置首选语言,则使用系统默认UI 语言。这是 Windows 本地化版本(XP 及更早版本)的语言,或安装期间选择的语言(Vista 及更高版本)。
Of course, this method of testing might be a little overkill because it's changing globalsettings (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.CurrentUICultureproperty. If your application is multi-threaded, you might want to set the DefaultThreadCurrentUICultureproperty 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 文化是按线程维护的,因此您可以仅针对应用程序的线程对其进行修改。为此,请设置该Thread.CurrentUICulture属性。如果您的应用程序是多线程的,您可能需要设置该DefaultThreadCurrentUICulture属性以确保其他线程选择正确的区域性。问题说你已经找到了这个,但我不清楚你为什么不想使用它。
Also, be careful about confusing the UI language with the locale; they are not the same. CurrentCultureis the locale, which sets things like date/number/time formats and the sort order. CurrentUICultureis the UI language, which deals with loading the correctly localized resources. They mightbe 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.
另外,请注意不要将 UI 语言与语言环境混淆;她们不一样。CurrentCulture是语言环境,它设置日期/数字/时间格式和排序顺序等内容。CurrentUICulture是 UI 语言,处理加载正确本地化的资源。他们可能是一样的,我想他们经常是,但他们不一定是。在某些情况下,用户可能希望它们有所不同;例如,如果他们说英语并且更喜欢本地化的英语版本,但想要查看根据他们的习惯格式化的日期和时间等内容。
回答by Dan
You can set UI culture System.Globalization.CultureInfo.CurrentUICultureon windows machine in: Control Panel\Clock, Language, and Region\Language:
您可以System.Globalization.CultureInfo.CurrentUICulture在 Windows 机器上设置 UI 文化Control Panel\Clock, Language, and Region\Language:
System.Globalization.CultureInfo.CurrentUICulture
System.Globalization.CultureInfo.CurrentUICulture
And in case if you want to set System.Globalization.CultureInfo.CurrentCulturein your windows machine go to Control Panel\Clock, Language, and Region,and select Region:
如果您想System.Globalization.CultureInfo.CurrentCulture在 Windows 机器中进行设置,请转到Control Panel\Clock, Language, and Region,然后选择区域:
System.Globalization.CultureInfo.CurrentCulture
System.Globalization.CultureInfo.CurrentCulture
In your code you can just use this to get those values:
在您的代码中,您可以使用它来获取这些值:
Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.CurrentUICulture;
Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CurrentCulture;
Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.CurrentUICulture;
Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CurrentCulture;
Source: CurrentCulture vs. CurrentUICulture
资料来源:CurrentCulture 与 CurrentUICulture
回答by Neolisk
So I tried to install a French language pack for testing purposes, using different ways and they all failed. Both offline and online installation, as is or after restart. Got error code 800736B3 (for online) or no code at all for offline installation. Tried System Update Readiness Tool for Windows 7(a 390MB msu package), which is a most commonly known way to fix this error code. Still got the same problems with both online and offline installers. Having spend around 4-5 hours on it in total, I'm starting to understand why @Cody recommended to keep using this instead (for testing purposes):
所以我尝试安装一个用于测试目的的法语语言包,使用不同的方法,但都失败了。离线和在线安装,原样或重启后。得到错误代码 800736B3(在线)或离线安装根本没有代码。尝试了适用于 Windows 7 的系统更新准备工具(一个 390MB 的 msu 包),这是修复此错误代码的最常见方法。在线和离线安装程序仍然存在相同的问题。总共花费了大约 4-5 个小时,我开始理解为什么@Cody 建议继续使用它(用于测试目的):
Thread.CurrentThread.CurrentUICulture = New CultureInfo("fr")

