Get current locale programmatically in magento2 [duplicate]
سؤال
I want to get current language of store. When I switch store as per store vise I want to get store language.
How can i get it?
المحلول
You can use \Magento\Store\Api\Data\StoreInterface
to get locale code
/**@var \Magento\Store\Api\Data\StoreInterface **/
protected $_store;
public function __construct(
\Magento\Store\Api\Data\StoreInterface $store,
.....
) {
$this->_store = $store;
}
you can check like this :
$this->_store->getLocaleCode() == 'en_EN';
Hope this code useful for you.
نصائح أخرى
Get your current store language scope using below way,
public function __construct(
\Magento\Framework\Locale\Resolver $locale
) {
$this->locale = $locale;
}
call inside phtml file,
$currentCode = $this->locale->getLocale();
if($currentCode == 'en_US'){
}
لا تنتمي إلى magento.stackexchange