Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento2 Magento 2:如何获取商店视图代码的当前语言?_Magento2_Magento2.1 - Fatal编程技术网

Magento2 Magento 2:如何获取商店视图代码的当前语言?

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

我试图为每个商店视图/语言显示一个自定义块。 因此,我想创建如下switch语句:

$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
的内容