获取除英语以外的其他语言的国家列表

时间:2011-11-02 10:09:55

标签: c# .net

我可以使用以下代码获取国家/地区名称列表,(从某些我无法记住的地方复制)

我的问题是,我是否可以获得其他语言的国家/地区列表,例如泰语?

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

3 个答案:

答案 0 :(得分:11)

  

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

     

DisplayName属性以.NET Framework的本地化版本的语言显示国家/地区名称。例如,DisplayName属性在英文版的.NET Framework上显示英语的国家/地区,,在西班牙语版本的.NET Framework上显示西班牙语

因此,.NET Framework中的每种语言都没有国家/地区名称列表,只有安装的.NET Framework所使用的语言。

答案 1 :(得分:5)

使用DisplayName(在当前的框架文化中为您提供名称)或NativeName(在原生文化中为您提供名称)而不是EnglishName

答案 2 :(得分:0)

很晚才回答:

在我的应用程序中,用户可以选择一种语言(应用程序支持的语言),并且在UI中,我需要以所选语言显示国家/地区名称。

我发现NuGet软件包IsoNames满足了这一目的。它提供了方法

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

从而克服了DisplayName暗含的限制。

相关问题