Tim Heuer
Tim Heuer

Reputation: 4311

What is the best way to enumerate Windows languages in C#?

I'm trying to enumerate the list of available/supported languages on a given Windows installation using C# in a full-trust client application. Best method?

Upvotes: 2

Views: 775

Answers (3)

Tim Heuer
Tim Heuer

Reputation: 4311

CultureInfo[] allCultures = CultureInfo.GetCultures(CultureTypes.NeutralCultures | CultureTypes.SpecificCultures);

Upvotes: 4

PhilPursglove
PhilPursglove

Reputation: 12589

You can get the set of available languages installed by using WMI and querying the MUILanguages property of the Win32_OperatingSystem class:

// There's most likely a better way to do this than using this searcher 
// but it's the most reliable way I've found
ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from win32_OperatingSystem");

ManagementObjectCollection osCollection = searcher.Get();

foreach (ManagementBaseObject os in osCollection)
{
    string[] languages = (string[])os.GetPropertyValue("MUILanguages");

    foreach (string language in languages)
    {
        System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(language);

        Console.WriteLine(culture.EnglishName);
    }

}

However the languages you get back from this are in the abbreviated format e.g. en-US rather than English (United States). I can't see a way round this to get the full language string other than to use a Dictionary of short codes and full descriptions and look up each language.

Upvotes: 0

Bala R
Bala R

Reputation: 108977

How about

 InputLanguageManager.Current.AvailableInputLanguages;

?

Upvotes: 0

Related Questions