4

I want to change a country name in magento 2.2.6. Say I want to change united kingdom to 'great britain'. All the countries are stored in a xml file at location

/vendor/magento/zendframework1/library/Zend/Locale/Data/en.xml

We can make the changes according to our locale file. I tried to change here but nothing happened (ofcourse I cleared all the caches).

In magento 1.9 I changed in the following file for this problem

/lib/Zend/Locale/Data/en.xml

So i tried to make the same change in locale folder in magento2 but nothing happened. I found a lot of questions on magento stack exchange related to this but none has a proper answer. So I was left on my own, what I did I changed all the files in magento 2.2 (including csv and xml), where I found united kingdom to great britain, cleared caches but to mu surprise I still get united kingdom (in country select box).

I know countries name are not stored in database and I have changed all the files where I could find united kingdom to great britain but still I get united kingdom. I have no more method I could try for. If anyone faced the problem and could guide me in right direction.

1
  • 2
    UK and GB are not the same. I just want to mention that – Philipp Sander Jan 29 '19 at 9:55
4

The country labels loaded using ICU. You can find more info in the Magento\Framework\Locale\Bundle\DataBundle class. Data is loading in the get method:

/**
 * Get resource bundle for the locale
 *
 * @param string $locale
 * @return \ResourceBundle
 */
public function get($locale)
{
    $locale = $this->cleanLocale($locale);
    $class = get_class($this);
    if (!isset(static::$bundles[$class][$locale])) {
        $bundle = $this->createResourceBundle($locale, $this->path);
        if (!$bundle && $this->path != 'ICUDATA') {
            $bundle = $this->createResourceBundle($locale, 'ICUDATA');
        }
        static::$bundles[$class][$locale] = $bundle;
    }
    return static::$bundles[$class][$locale];
}

To change country label you can create your own bundle (link to detailed SO answer).


Another way is to create a plugin for the \Magento\Framework\Locale\TranslatedLists::getCountryTranslation($value, $locale = null) method or \Magento\Directory\Model\Country::getName($locale = null) method and change whatever you want. It's much easiest way, I think.

1

I followed the below link and it helps me to add a new country

Add new nation into nation's list in Magento 2.3.5

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