Reputation: 6618
Is there a way to detect the Language of the OS from within a c# class?
Upvotes: 15
Views: 29019
Reputation: 5551
All of the answers above seem to only get you the OS installed culture (at best). I ran into an issue where I needed the actual display language being used in Windows. i.e. the user installed the default en-US Windows install, but then added a language pack for German (de-DE) and set that as their display language.
To get that, I used System.Windows.Input.InputLanguageManager.Current.CurrentInputLanguage
Upvotes: 1
Reputation: 13575
"System.Globalization.CultureInfo.CurrentUICulture.DisplayName"
. This is exactly what you want.
Upvotes: 5
Reputation: 61
Means that if the system locale on Region and Language, you can use Win32 API function GetSystemDefaultLCID. The signiture is as follow:
[DllImport("kernel32.dll")]
static extern uint GetSystemDefaultLCID();
GetSystemDefaultLCID function returns the LCID. It can map language string from the folowing table. Locale IDs Assigned by Microsoft
Upvotes: 3
Reputation: 444
Unfortunately, the previous answers are not 100% correct.
The CurrentCulture
is the culture info of the running thread, and it is used for operations that need to know the current culture, but not do display anything. CurrentUICulture
is used to format the display, such as correct display of the DateTime
.
Because you might change the current thread Culture
or UICulture
, if you want to know what the OS CultureInfo
actually is, use CultureInfo.InstalledUICulture
.
Also, there is another question about this subject (more recent than this one) with a detailed answer:
Get operating system language in c#.
Upvotes: 26
Reputation: 44307
Do you mean whether the machine is configured (e.g.) with English, French or Japanese?
Have a look at the CultureInfo class - particularly CurrentCulture, which is initialised from the OS current regional settings.
Upvotes: 3
Reputation: 9240
With the System.Globalization.CultureInfo
class you can determine what you want.
With CultureInfo.CurrentCulture
you get the system set culture, with CultureInfo.CurrentUICulture
you get the user set culture.
Upvotes: 9