Magento2 Magento 2:如何获取商店视图代码的当前语言?
我试图为每个商店视图/语言显示一个自定义块。 因此,我想创建如下switch语句:Magento2 Magento 2:如何获取商店视图代码的当前语言?,magento2,magento2.1,Magento2,Magento2.1,我试图为每个商店视图/语言显示一个自定义块。 因此,我想创建如下switch语句: $lang = // Get language code or store view code here; switch ($lang) { case 'en': // English block break; case 'nl': // Dutch block break; default: // Du
$lang = // Get language code or store view code here;
switch ($lang) {
case 'en':
// English block
break;
case 'nl':
// Dutch block
break;
default:
// Dutch block
break;
}
我怎么能得到这个?我需要它在这个文件中
\app\design\frontend\Venustheme\flority\Ves\u Themesettings\templates\header\default.phtml
在与模板文件对应的块类的\Magento\Store\Api\Data\StoreInterface
中使用它
例如:
/**@var \Magento\Store\Api\Data\StoreInterface **/
protected $_store;
public function __construct(
\Magento\Store\Api\Data\StoreInterface $store,
.....
) {
$this->_store = $store;
}
public function getLocaleCode()
{
return $this->_store->getLocaleCode();
}
使用$block->getLocaleCode()
从模板文件调用getLocaleCode()
函数,该函数应返回类似en\u en
的内容