7

I am new to this Magento community and stuck at a very basic thing. I am getting the region(state) name from a customer address with this code

$billingAddress = Mage::getModel('customer/address')->load($billingAddressId);
$RegionName = $billingAddress->getRegion();

Now some regions are being returned in locale language. One example is - Oberösterreich. I want this to be translated in default en_GB language.

I was facing a similar issue with country name as well, though figured out a solution for that as -

$locale = new Zend_Locale('en_GB');
$countries = $locale->getTranslationList('Territory', $locale->getLanguage(), 2);
$countryName = $countries[$billingAddress->getCountryId()];

This was converting the returned name from Deutschland to Germany

I am seeking the same solution for the region name as well. Any help would be appreciated.

  • 1
    There is no translated names of regions in Magento. Did You check this magento.stackexchange.com/questions/158250/… – BartZalas May 24 at 9:15
  • @BartZalas I've checked by getting region name after changing the site's default language to English. The region Oberösterreich came with the same name again. I think there is no other translation exist for this name and its a static string there. Am I right? – Anant May 29 at 10:23
  • They are but they located in database. The fastest way is to change manually in database. Also read comment from my link – BartZalas May 29 at 16:37
3
+25

For getting the region in your locale you just need to add it to directory_country_region_name table and based on the stores locale it will be fetched correctly. So, if you have a region like below:

region_id,country_id,code,default_name

1001, IN, DE, Delhi

then the directory_country_region_name table data will look like below for en_US locale:

locale,region_id,name

'en_US','1001','New Delhi'

How to get the localized region id based on the current region:

$billingAddress = Mage::getModel('customer/address')->load($billingAddressId);
$regionId = $billingAddress->getRegionId();

$regionModel = Mage::getModel('directory/region')->load($regionId);
$regionName = $regionModel->getName();

Based on the current store locate it will fetch the data from table directory_country_region_name If not found in the table directory_country_region_name then default will be loaded.

  • I am unable to get your answer. Do you mean I need to convert and save all regions name on my own in a table? As I have $billingAddressId, can you share some code snippet that I need to follow to get region name in my desired language. – Anant May 29 at 10:21
  • @Anant, Let me edit my answer to address your query – Arif Ahmad May 30 at 5:58
  • The code you've provided is still returning the region in the same locale and not in the converted locale :( – Anant Jun 19 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.