How to Get country name from country code in Magento 2?
Create Block file,
public function __construct(
\Magento\Directory\Model\CountryFactory $countryFactory
) {
$this->_countryFactory = $countryFactory;
}
public function getCountryname($countryCode){
$country = $this->_countryFactory->create()->loadByCode($countryCode);
return $country->getName();
}
Call from phtml file,
echo $block->getCountryname($countryCode);
We can use Magento\Directory\Api\CountryInformationAcquirerInterface
to get the country info:
/** @var \Magento\Directory\Api\CountryInformationAcquirerInterface $country */
/** @var \Magento\Directory\Api\Data\CountryInformationInterface $data */
$data = $country->getCountryInfo($data['country_id']);
$data->getFullNameEnglish();
$data->getFullNameLocale();
See more here about the returned values: Magento\Directory\Api\Data\CountryInformationInterface