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:
/** @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());

Leave a Reply