获取 CultureInfo 中的当前语言

发布于 2024-10-03 04:37:44 字数 99 浏览 1 评论 0原文

如何使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

尸血腥色 2024-10-10 04:37:44

我认为这样的东西会给你当前的文化信息:

CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;

这是你正在寻找的吗?

I think something like this would give you the current CultureInfo:

CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;

Is that what you're looking for?

酒废 2024-10-10 04:37:44

这就是我用过的:

var culture = System.Globalization.CultureInfo.CurrentCulture;

并且它正在工作:)

This is what i used:

var culture = System.Globalization.CultureInfo.CurrentCulture;

and it's working :)

望喜 2024-10-10 04:37:44

使用以下命令检索当前系统语言:

  CultureInfo.InstalledUICulture

“获取代表随操作系统安装的区域性的 CultureInfo”。

已安装的UICulture

要将其设置为线程使用的默认语言:

   System.Globalization.CultureInfo.DefaultThreadCurrentCulture=CultureInfo.InstalledUICulture;

Current system language is retrieved using :

  CultureInfo.InstalledUICulture

"Gets the CultureInfo that represents the culture installed with the operating system."

InstalledUICulture

To set it as default language for thread use :

   System.Globalization.CultureInfo.DefaultThreadCurrentCulture=CultureInfo.InstalledUICulture;
淡忘如思 2024-10-10 04:37:44

我尝试了 {CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;} 但它对我不起作用,因为我的 UI 文化与我的数字/货币文化不同。所以我建议你使用:

CultureInfo currentCulture = Thread.CurrentThread.CurrentUICulture;

这将为你提供 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:

CultureInfo currentCulture = Thread.CurrentThread.CurrentUICulture;

This will give you the culture your UI is (texts on windows, message boxes, etc).

素食主义者 2024-10-10 04:37:44

要获取 2 个字符的 ISO 639-1 语言标识符,请使用:

System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;

To get the 2 chars ISO 639-1 language identifier use:

System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
诠释孤独 2024-10-10 04:37:44
Windows.System.UserProfile.GlobalizationPreferences.Languages[0]

这是获取当前设置的系统语言的正确方法。系统语言设置与您想要从中获取语言的文化设置完全不同。

例如:用户可以同时使用“en-GB”语言和“en-US”文化。使用 CurrentCulture 和其他文化,您将得到“en-US”,希望您能明白其中的区别(这对于 GB-US 可能不明显,但对于其他语言?)

Windows.System.UserProfile.GlobalizationPreferences.Languages[0]

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文