14

I can get the list of country names using below code, (copied from somewhere i can't remember)

My question is, can i get the list of countries in other languages such as Thai ?

    /// <summary>
    /// method for generating a country list, say for populating
    /// a ComboBox, with country options. We return the
    /// values in a Generic List<T>
    /// </summary>
    /// <returns></returns>
    public static List<string> GetCountryList()
    {
        //create a new Generic list to hold the country names returned
        List<string> cultureList = new List<string>();

        //create an array of CultureInfo to hold all the cultures found, these include the users local cluture, and all the
        //cultures installed with the .Net Framework
        CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);

        //loop through all the cultures found
        foreach (CultureInfo culture in cultures)
        {
            //pass the current culture's Locale ID (http://msdn.microsoft.com/en-us/library/0h88fahh.aspx)
            //to the RegionInfo contructor to gain access to the information for that culture
            RegionInfo region = new RegionInfo(culture.LCID);

            //make sure out generic list doesnt already
            //contain this country
            if (!(cultureList.Contains(region.EnglishName)))
                //not there so add the EnglishName (http://msdn.microsoft.com/en-us/library/system.globalization.regioninfo.englishname.aspx)
                //value to our generic list
                cultureList.Add(region.EnglishName);
        }
        return cultureList;
    }
Prasanth
  • 3,029
  • 31
  • 44
Sarawut Positwinyu
  • 4,974
  • 15
  • 54
  • 80

3 Answers3

12

http://msdn.microsoft.com/en-us/library/system.globalization.regioninfo.displayname.aspx

The DisplayName property displays the country/region name in the language of the localized version of .NET Framework. For example, the DisplayName property displays the country/region in English on the English version of the .NET Framework, and in Spanish on the Spanish version of the .NET Framework.

So it looks like there's no list of country names in each language in the .NET Framework, only in the language that the installed .NET Framework is.

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • Does that mean that a set currentUiCulture to 'fr' will show a country name 'Allemagne' ? which means Germany in english. – Pascal Aug 26 '16 at 23:34
  • 1
    @Pascal no, it will be in the language that the .NET Framework was installed in. – CodeCaster Aug 27 '16 at 00:16
7

Either use DisplayName (gives you the name in the current Framework Culture) or NativeName (gives you the name in the native culture) instead of EnglishName.

Yahia
  • 69,653
  • 9
  • 115
  • 144
  • This is a much better answer then the one that was accepted. Its a shame since the accepted answer is sort of incorrect. – Security Hound Nov 02 '11 at 11:58
  • 9
    What's wrong about my answer? NativeName gives you the name in that culture, not in the current culture. So South Afrika's NativeName is "Suid Afrika", and Morocco's NativeName is "المملكة المغربية". It's not possible to get all country names based on one culture, except English or the language of the installation of the .NET Framework. – CodeCaster Nov 02 '11 at 12:04
0

Pretty late answer:

In my application the user can select a language (among languages that the application supports) and in the UI I need to display country names in the selected language.

I found that NuGet package IsoNames fullfills that purpose. It provides method

IsoNames.CountryNames.GetName(CultureInfo culture, string countrycode);

and thus overcomes the restrictions implied with the DisplayName.

user7399085
  • 220
  • 1
  • 12