15

Is there a way to detect the Language of the OS from within a c# class?

7 Answers 7

26

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

Sign up to request clarification or add additional context in comments.

3 Comments

That's not right either. CurrentCulture is used for formatting dates and numbers and such, and CurrentUICulture is used to look up resources.
No Sven, in this one, you are actually wrong and Mihai has written the correct thing: the CultureInfo.InstalledUICulture seems to be the actual OperatingSystem's predefined culture info. I've just checked at msdn.microsoft.com/en-us/library/… and they are clearly saying that this is the system-default one!
Not true quetzalcoati, sven is right. If I change the Date, Time and Number formats in control panel this will change CurrentCulture, It will not change CurrentUICulture. CurrentUICulture is used or should be used to display the UI elements. Please do not use CurrentCulture for this as an end-user might want to display numbers different but still wants an otherwise consistent UI. She couldn't be bothered with the Installed culture though.
9

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.

2 Comments

Your description of the two properties is wrong. CultureInfo.CurrentCulture is the culture that is used to format dates, numbers, etc. and is initialized from the users locale (regional settings). CultureInfo.CurrentUICulture is the culture used by the resource manager to look up string resources, and is initialized from the OS's UI language.
Sven pointed out the problem correctly, but the actual answer is elsewhere. Please see the Mihai's answer below and the link to MSDN I've included in a comment
5

"System.Globalization.CultureInfo.CurrentUICulture.DisplayName". This is exactly what you want.

Comments

3

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.

2 Comments

I think we are on the same page but to precisely answer what he is asking: the answer is "System.Globalization.CultureInfo.CurrentUICulture.DisplayName"
Have a look instead at CurrentUICulture instead. CurrentCulture is not really what you want. (See my comments above)
3

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

Comments

1

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

Comments

0

System.Threading.Thread.CurrentThread.CurrentCulture

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.