Gilad Novik
Gilad Novik

Reputation: 4604

List of countries in native language

I'm using a webservice which provides me a list of countries to choose from as 2 letters ('us' for USA, 'es' for Spain etc.).

I need to present it to the user and send back the selection.

Is there an API on iOS to convert the country code to a country name - based on the current language? I know I can have a static mapping of codes to countries, but I would like to support other languages than English.

For example, I would like to display "Spain" for 'es' when using english locale and "Espanya" when using spanish locale.

Upvotes: 1

Views: 500

Answers (3)

Gilad Novik
Gilad Novik

Reputation: 4604

OK, apparently it's easier than I though: I'm posting the answer if anyone else will have the same problem:

NSString* name=[[NSLocale currentLocale] displayNameForKey:NSLocaleCountryCode value:@"ca"];

That's it :)

Upvotes: 0

GreyHands
GreyHands

Reputation: 1794

I used this, maybe it suits your needs too:

NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
NSString *countryName = [locale displayNameForKey: NSLocaleCountryCode value: countryCode];
[locale release];

Upvotes: 2

I've found this one, but I suggest you to build your own solution. Free APIs give you limits that maybe limit your app usage Link

Upvotes: 0

Related Questions