Magento: get country name in a specified language

Magento: get country name in a specified language

August 15, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: get country name in a specified language

Magento: Retrieve Country Name in a Specified Language

In Magento, you can easily retrieve country names using the Mage::getModel('directory/country') model. However, by default, it returns the name in the current store’s language configuration. If you want to get the translation for a specific language regardless of the customer’s frontend language setting, follow these steps.

Understanding the Problem

When you use Mage::getModel('directory/country')->loadByCode('DE')->getName(), Magento retrieves the country name based on the current store’s default locale. If your default locale is set to English, it will return “Germany”. If it’s German, it will return “Deutschland”.

The issue arises when you want to get the translation for a specific language independently of the frontend customer’s language setting.

The Solution: Magical Models and Translations

Magento uses magical models (Mage::getModel()) which are bound to the current store scope. To retrieve a translated value independent of the store scope, we need to use Mage::app()->getLocale()->getTranslation('country_name', 'de'). This method retrieves the country name translation for the specified language.

Code Example: Getting Country Name in German

$countryName = Mage::app()->getLocale()->getTranslation('country_name', 'de');

In this example, Mage::app()->getLocale() gets the current application’s locale object. The method getTranslation('country_name', 'de') retrieves the translation for “country_name” in German.

Best Practices and Tips

  • Always use Mage::app()->getLocale()->getTranslation(...) outside of store-specific contexts to ensure you get the correct translation.
  • If you want to retrieve all country names in a specific language, you can iterate through the directory model:
$countryCollection = Mage::getModel('directory/country')->getCollection();
foreach ($countryCollection as $country) {
    echo $country->getName() . " => " . Mage::app()->getLocale()->getTranslation($country->getName(), 'de') . "\n";
}

Conclusion

In Magento, retrieving a country name in a specific language independently of the frontend setting is a common requirement. By using Mage::app()->getLocale()->getTranslation(...) outside of store-specific contexts, you can ensure that your code always retrieves the correct translation.

Remember to always keep your Magento installation up-to-date for optimal performance and security. At Laravel Company, we specialize in Magento development services, ensuring your e-commerce platform runs smoothly and efficiently.

If you found this guide helpful, please share it with other developers in the Magento community. Happy coding!

Note: The code examples provided are based on Magento 1.x versions. In Magento 2.x and later, the architecture has been revamped, but the basic principles remain similar. You would need to adjust the syntax accordingly for newer versions.

The post Magento: get country name in a specified language first appeared on Laravel Company Blog.

Themes Configuration Customers Errors

Our network