Get current language in CultureInfo

 ̄綄美尐妖づ 提交于 2019-11-26 20:51:21

问题


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.


回答1:


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

CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;

Is that what you're looking for?




回答2:


This is what i used:

var culture = System.Globalization.CultureInfo.CurrentCulture;

and it's working :)




回答3:


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;



回答4:


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




回答5:


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

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


来源:https://stackoverflow.com/questions/4208244/get-current-language-in-cultureinfo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!