1,105,402 Community Members

Issues with CultureInfo.GetCultures() - Get Country names in a Country

Member Avatar
Diogo Martinho
Light Poster
41 posts since Apr 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hello.
I'm currently facing an issue with my code related to the way CultureInfo.GetCultures method is sending me the list of countries.

I have this in my getCountries method:

System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); 
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB"); 
var cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);

Which retrieves me a list of Cultures in associated to English Culture.

I was trying to do something like

public List<String> getCountriesNamesbyCountry(string countrycode){

    System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(countrycode); 
    System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(countrycode); 
    var cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);

    var cultureList = new List<String>();

       foreach (CultureInfo cul in cultures)
        {
            var country = new RegionInfo(cul.LCID);

            if (!cultureList.Contains(country.DisplayName))
            {
                cultureList.Add(country.DisplayName);
            }
        }

        return cultureList;
}

If I try to do this

List<String> en = getCountriesNamesbyCountry("en");
List<String> es = getCountriesNamesbyCountry("es");

Both lists will give me a list of country names in english.
What am I doing wrong >.<?

Member Avatar
pritaeas
mod_pritaeas
11,297 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,832 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
0
 

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

See the Remarks section. The DisplayName is taken from your installed version of .NET, so even if you change the culture, your installed version probably does not have the correct resources installed.

Member Avatar
Diogo Martinho
Light Poster
41 posts since Apr 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

What should I do then in that case?

Member Avatar
pritaeas
mod_pritaeas
11,297 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,832 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
0
 

Build a resource yourself, which you can then include and use in your application. Perhaps you can find one online. There must've been more people facing this issue.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: