Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get country name from country code?

Tags:

magento

$collection = Mage::getModel('custom/table')->getCollection();

I have one custom table and there is one field country_code.

Now I am passing this $collection to my javascript and using variables in that.

Now I want to display country name instead of country code.

Is there any way from which I can add country name in my collection using join query or any way else ?

so before passing to js I want country name in my collection object.

like image 332
Akhilesh Patel Avatar asked Feb 03 '14 10:02

Akhilesh Patel


People also ask

How do you find the country code of a country?

Locale loc = new Locale("NL"); loc. getCountry();

Is country code a name?

ARE is the three-letter country abbreviation for United Arab Emirates.

What is country ID?

ID is the two-letter country abbreviation for Indonesia.

How do I use country code?

Country codes are a group of numbers you enter before dialing the number of the person in the country you are calling. The country code is entered after the international calling code or prefix. Each country has its own unique code. For example, the country code for the United States is +1.


2 Answers

Magento stores the country names in locale files so that you can change the country name based on your language.

If you have the country code and you want to get the country name use the below code:

$country_name=Mage::app()->getLocale()->getCountryTranslation($country_code);

Or you can also try

// $countryCode looks like "US"
$country = Mage::getModel('directory/country')->loadByCode($countryCode);
echo $country->getName(); /

Please let me know if i can help you more.

like image 181
liyakat Avatar answered Sep 22 '22 16:09

liyakat


you can get country name from

$countryModel = Mage::getModel('directory/country')->loadByCode('country_code');

$countryName = $countryModel->getName();
like image 42
Keyur Shah Avatar answered Sep 22 '22 16:09

Keyur Shah