21

I know of three ways to get a full language name of a CultureInfo object.

CultureInfo.DisplayName   
CultureInfo.NativeName  
CultureInfo.EnglishName

DisplayName gives the name in the installed .net language.
NativeName gives the name in 'CultureInfos' language.
EnglishName gives the name in English (surprisingly...)

So for CultureInfo de-DE this gives (on an English .net installation)
German
Deutsch
German

Now my question: Is there a way to ask for the language name of de-DE in another language? E.g. I want the language name of de-DE in Dutch (which would be 'Duits').

Yodah
  • 283
  • 1
  • 2
  • 7

3 Answers3

15

This functionality isn't built into the .NET Framework

Maybe look at Google Translate API

Dead account
  • 19,587
  • 13
  • 52
  • 82
  • 2
    Thats what I was afraid for. The only free translation you get is English, the .NET installation language (if that is different) and the translation in the native CultureInfo language. I'll have to weigh off the gains of using the google translate api to the efforts. – Yodah Mar 12 '10 at 14:08
5

Example for CultureInfo.EnglishName:

    public CultureInfo GetCultureInfo(string EnglishName)
    {
        foreach (CultureInfo info in CultureInfo.GetCultures(CultureTypes.AllCultures))
        {
            if (info.EnglishName == EnglishName)
                return new CultureInfo(info.Name);
        }

        return null;
    }
Mr.Angel
  • 117
  • 1
  • 4
  • Thanks, I was looking for a way to get culture info based on the language name, this is what I needed – Naomi Jul 02 '15 at 20:01
1

In principle the following code works:

private static ResourceManager resourceManager = new ResourceManager("mscorlib", typeof(int).Assembly);

public static string CultureName(CultureInfo culture, CultureInfo displayCulture)
{
    return resourceManager.GetString("Globalization.ci_" + culture.Name, displayCulture);
}

However there are important limitations:

  • It relies on undocumented behaviour, so it can break with updates of Windows or .NET
  • The display language needs to be installed on the Computer you run it on. You can install additional languages, depending on the edition of Windows you're using.

    On most computers there is only one installed language, making this a pointless exercise in most cases.

CodesInChaos
  • 106,488
  • 23
  • 218
  • 262