dnur
dnur

Reputation: 709

Get operating system language in c#

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

Upvotes: 42

Views: 79185

Answers (4)

Jay
Jay

Reputation: 1

Don't mistake locales for UI language. Locales are about formatting numbers and dates and such. Also, there are independent settings for OS and for Apps.

Upvotes: 0

theking2
theking2

Reputation: 2783

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.

Upvotes: 31

Nicholas Carey
Nicholas Carey

Reputation: 74177

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 ;
}

Upvotes: 82

Hans Passant
Hans Passant

Reputation: 941218

using System;

class Program {
    static void Main(string[] args) {
        Console.WriteLine("You are speaking {0}",
            System.Globalization.CultureInfo.CurrentCulture.EnglishName);
        Console.ReadLine();
    }
}

Upvotes: 3

Related Questions