zend framework 2 get locale from view PhpRenderer

浪子不回头ぞ 提交于 2019-12-25 01:01:13

问题


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!


回答1:


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.




回答2:


<?php echo $this->plugin('translate')->getTranslator()->getLocale(); ?>

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



来源:https://stackoverflow.com/questions/13075506/zend-framework-2-get-locale-from-view-phprenderer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!