Magento2 : Get List of Locale For All Stores

You can use the following Magento2 code snippet in your module or custom PHP script to get list of locale for all stores:
<?php
/** @var MagentoFrameworkAppObjectManager $objManager **/
$objManager = MagentoFrameworkAppObjectManager::getInstance();

/** @var MagentoStoreModelStoreManagerInterface|MagentoStoreModelStoreManager $storeManager **/
$storeManager = $objManager->get('MagentoStoreModelStoreManagerInterface');
$stores = $storeManager->getStores($withDefault = false);

//Get scope config
/** @var MagentoFrameworkAppConfigScopeConfigInterface|MagentoFrameworkAppConfig $scopeConfig **/
$scopeConfig = $obj->get('MagentoFrameworkAppConfigScopeConfigInterface');

//new empty array to store locale codes
$localeForAllStores = [];

//To get list of locale for all stores;
foreach($stores as $store) {
    $localeForAllStores[] = $scopeConfig->getValue('general/locale/code', MagentoStoreModelScopeInterface::SCOPE_STORE, $store->getStoreId());
}
?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s