Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get operating system language in c#

Tags:

c#

How can we get current operating system language using Win32_OperatingSystem Class and OSLanguage variable in c#? Thanks..

like image 631
dnur Avatar asked Apr 18 '11 23:04

dnur


2 Answers

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 ; } 
like image 110
Nicholas Carey Avatar answered Sep 20 '22 14:09

Nicholas Carey


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.

like image 37
theking2 Avatar answered Sep 17 '22 14:09

theking2