zend framework 2 get locale from view PhpRenderer

2019-08-16 10:10发布

How I can obtain traslator locale in my view?

I want to do it starting from the variable $this (the PhpRenderer of the view). i.e. I don't want use onBootstrap nor ActionController because I don't care to have a view variables.

Thank you!

2条回答
Luminary・发光体
2楼-- · 2019-08-16 10:29
<?php echo $this->plugin('translate')->getTranslator()->getLocale(); ?>

See: Get local value in layout or view in Zend Framework 2

查看更多
Lonely孤独者°
3楼-- · 2019-08-16 10:34

You should try:

<?php echo \Locale::getDefault(); ?>

Many of the I18n classes make reference to PHP's Locale class (http://www.php.net/locale) - so in my opinion that would be a good starting point.

查看更多
登录 后发表回答