获取 CultureInfo 中的当前语言
如何使用CultureInfo
识别操作系统的语言?例如,如果Windows中的语言设置为法语,我需要识别法语并加载fr
资源文件数据。
How to identify the operating system's language using CultureInfo
? E.g. if the language in Windows is set to French, I need to identify French and load the fr
resource files data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我认为这样的东西会给你当前的文化信息:
这是你正在寻找的吗?
I think something like this would give you the current CultureInfo:
Is that what you're looking for?
这就是我用过的:
并且它正在工作:)
This is what i used:
and it's working :)
使用以下命令检索当前系统语言:
“获取代表随操作系统安装的区域性的 CultureInfo”。
已安装的UICulture
要将其设置为线程使用的默认语言:
Current system language is retrieved using :
"Gets the CultureInfo that represents the culture installed with the operating system."
InstalledUICulture
To set it as default language for thread use :
我尝试了
{CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;}
但它对我不起作用,因为我的 UI 文化与我的数字/货币文化不同。所以我建议你使用:这将为你提供 UI 的文化(窗口上的文本、消息框等)。
I tried
{CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;}
but it didn`t work for me, since my UI culture was different from my number/currency culture. So I suggest you to use:This will give you the culture your UI is (texts on windows, message boxes, etc).
要获取 2 个字符的 ISO 639-1 语言标识符,请使用:
To get the 2 chars ISO 639-1 language identifier use:
这是获取当前设置的系统语言的正确方法。系统语言设置与您想要从中获取语言的文化设置完全不同。
例如:用户可以同时使用“en-GB”语言和“en-US”文化。使用 CurrentCulture 和其他文化,您将得到“en-US”,希望您能明白其中的区别(这对于 GB-US 可能不明显,但对于其他语言?)
This is the correct way to obtain the currently set system language. System language setting is completely different than culture setting from which you all want to get the language.
For example: User may use "en-GB" language along with "en-US" culture at the same time. Using CurrentCulture and other cultures you will get "en-US", hope you get the difference (that may be innoticable with GB-US, but with other languages?)