Get operating system language in c#
Solution 1:
Like this:
static int Main( string[] argv )
{
CultureInfo ci = CultureInfo.InstalledUICulture ;
Console.WriteLine("Default Language Info:" ) ;
Console.WriteLine("* Name: {0}" , ci.Name ) ;
Console.WriteLine("* Display Name: {0}" , ci.DisplayName ) ;
Console.WriteLine("* English Name: {0}" , ci.EnglishName ) ;
Console.WriteLine("* 2-letter ISO Name: {0}" , ci.TwoLetterISOLanguageName ) ;
Console.WriteLine("* 3-letter ISO Name: {0}" , ci.ThreeLetterISOLanguageName ) ;
Console.WriteLine("* 3-letter Win32 API Name: {0}" , ci.ThreeLetterWindowsLanguageName ) ;
return 0 ;
}
Solution 2:
Perhaps to make this a bit clearer (or not) the three cultures Installed, CurrentUI and Current are set in a not so obvious way.
If in the Control panel on a English UK system (Windows 10 Technical Preview) I specify a German (Swiss) date / time format the output of the following program:
CultureInfo ci = CultureInfo.InstalledUICulture;
Console.WriteLine("Installed Language Info:{0}", ci.Name);
ci = CultureInfo.CurrentUICulture;
Console.WriteLine("Current UI Language Info: {0}", ci.Name);
ci = CultureInfo.CurrentCulture;
Console.WriteLine("Current Language Info: {0}", ci.Name);
is thus:
Installed Language Info:en-GB
Current UI Language Info: en-GB
Current Language Info: de-CH
Meaning that Installed cannot be influenced but is set at install, but CurrentUI and Current can differ. Where CurrentUI probable means the localization of the OS (language settings) and Current only says something about how numbers dates and time is displayed (regional settings).
To often have I come across installation programs that take Current for the preferred language where it would probably give a more consistent end-user experience if instead CurrentUI was used.
Solution 3:
using System;
class Program {
static void Main(string[] args) {
Console.WriteLine("You are speaking {0}",
System.Globalization.CultureInfo.CurrentCulture.EnglishName);
Console.ReadLine();
}
}