A. Tapper
A. Tapper

Reputation: 1271

Any country name in current default locale

What I want do do is to provide a ISO 3166-1 country code and retrive the name of that country in the current locale. For those of you who are familiar with iPhone, I have an an example of exactly what I want to do:

NSLocale* currentLocale = [NSLocale currentLocale];
NSString* countryName = [currentLocale displayNameForKey:NSLocaleCountryCode value:@"NO"];

In this case the variable countryName would contain "Norway" given the iPhone was running in an english locale.
What I have understood so far is that to get the current locale in the Android SDK by a simple static method of the Locale class.

Locale currentLocale = Locale.getDefault();

But Im stuck here...

Upvotes: 4

Views: 2112

Answers (1)

zapl
zapl

Reputation: 63955

Locale l = new Locale("en", "NO");
String norway = l.getDisplayCountry();

works for me. Just replace "NO" by the country you want and it should give you the name in your current default locale. The "en" is just there to fill in some language but it should not matter which you use (At least I hope that works for all combinations - have not tested them all)

Upvotes: 6

Related Questions