Any country name in the current standard

I want to do this in order to provide the ISO 3166-1 country code and get the name of this country in the current region. For those of you familiar with the iPhone, I have an example of exactly what I want to do:

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

In this case, the countryName variable will contain "Norway", given that the iPhone works in the 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 I'm stuck here ...

+4
source share
1 answer
 Locale l = new Locale("en", "NO"); String norway = l.getDisplayCountry(); 

works for me. Just replace "NO" with the country you want, and it should indicate the name in the current standard by default. "en" just there to fill in some kind of language, but it doesn’t matter what you use (at least I hope it works for all combinations - did not check them all)

+6
source

Source: https://habr.com/ru/post/1401788/


All Articles