You can get the current store’s, store code value in Magento 2.
You need to use Magento\Store\Model\StoreManagerInterface interface for fetching current store locale.
I have given a demo using Block Class,
<?php namespace Rbj\Test\Block; use Magento\Framework\View\Element\Template; use Magento\Store\Model\StoreManagerInterface; use Magento\Framework\View\Element\Template\Context; class Locale extends Template { /** * @var StoreManagerInterface */ private $storeManager; public function __construct( Context $context, StoreManagerInterface $storeManager, array $data = [] ) { $this->storeManager = $storeManager; parent::__construct($context,$data); } public function getStoreCode() { return $this->storeManager->getStore()->getCode(); }
Call from template, $block->getStoreCode();
If your store URL like,
http://magento2.docker/default (English USA)
Result:default
http://magento2.docker/en_ca (English Canada)
Result: en_ca
http://magento2.docker/fr_ca (French Canada)
Result: fr_ca