Getting Country Name from Country Code

Get country name from country code

try like this

Locale loc = new Locale("","NL");
loc.getDisplayCountry();

Hope this will help out.

Retrieve country name using country code in app language not phone locale language

You just need to specify the language when initializing your Locale:

struct Country {
static func locale(for regionCode: String, language: String = "en") -> String? {
Locale(identifier: language + "_" + regionCode)
.localizedString(forRegionCode: regionCode)
}
}


Country.locale(for: "DE")                  // "Germany"
Country.locale(for: "DE", language: "de") // "Deutschland"

If you would like to automatically select the language based on the country/region code:

struct Country {
static func locale(for regionCode: String) -> String? {
let languageCode = Locale(identifier: regionCode).languageCode ?? "en"
return Locale(identifier: languageCode + "_" + regionCode)
.localizedString(forRegionCode: regionCode)
}
}


Country.locale(for: "DE")   // "Deutschland"

How to get country name from country code in javascript

You can use Intl.DisplayNames for this purpose, standard JS api, but not with full browser support yet (needs polyfills for Firefox & Safari as of January 2021).

Usage:

let regionNames = new Intl.DisplayNames(['en'], {type: 'region'});
regionNames.of('US'); // "United States"

Details:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames

Get country name String from country code int

Now an implementation of country code (ISO 3166-1 alpha-2/alpha-3/numeric) list as Java enum is available at GitHub under Apache License version 2.0.

Example:

int c_code=profile.getPersonnalInformation().getAddress().getCountry());// 392

CountryCode cc = CountryCode.getByCode(c_code);

String country_name=cc.getName(); // "Japan"

Gradle

dependencies {

compile 'com.neovisionaries:nv-i18n:1.20'

}

Github

https://github.com/TakahikoKawasaki/nv-i18n

Getting country name from country code

Swift 3

func countryName(from countryCode: String) -> String {
if let name = (Locale.current as NSLocale).displayName(forKey: .countryCode, value: countryCode) {
// Country name was found
return name
} else {
// Country name cannot be found
return countryCode
}
}

Get country name from country code in .net

This is as simple as that:

var name = "Germany";
var allRegions = CultureInfo.GetCultures(CultureTypes.SpecificCultures).Select(x => new RegionInfo(x.LCID));
var germanyCode = allRegions .FirstOrDefault(region => region.EnglishName == name)?.Name;

Note, that when the germanyCode is null then somebody messed up the English name.

Get country name from ISO code in Javascript

You can try Intl.DisplayNames() of ECMAScript Internationalization API Intl:

var getCountryNames = new Intl.DisplayNames(['en'], {type: 'region'});
console.log(getCountryNames.of('AL')); // "Albania"

How to get a list of country codes in WooCommerce

You can use WC()->countries->get_countries() and then use the array key

So you get:

// Get all countries key/names in an array:
$countries = WC()->countries->get_countries();

echo '<select name="countries">';

foreach ( $countries as $code => $country ) {
echo '<option value="' . $code . '">' . $code . '</option>';
}

echo '</select>';


  • $countries = countries keys/names in an array
  • $code = country code (key)
  • $country = country name


Related Topics



Leave a reply



Submit