Zend框架2:如何设置全局语言环境? [英] Zend framework 2 : How to set locale globaly?
本文介绍了Zend框架2:如何设置全局语言环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须根据用户想要的语言动态更改语言环境.
I have to change the locale dynamically depending which language the user wants.
我可以像这样在Application/Module.php中设置语言环境:
I can set the locale in the Application/Module.php like this :
public function onBootstrap(MvcEvent $e)
{
$translator = $e->getApplication()->getServiceManager()->get('translator');
$translator->setLocale('hu_HU');
}
但是,如果我想更改语言,该如何在控制器中执行此操作?我尝试了此操作,但是在此之后,我只能更改此请求的语言环境,而不能更改全局语言.
But, how can I do this in the controller, if I want to change languages ? I tried this, but after this I can change the locale only for this one request and not global.
$translator = $this->getServiceLocator()->get('translator');
$translator->setLocale('srb_SRB');
推荐答案
在配置级别设置默认语言环境!参见 #61 of module.config.php
from ZendSkeletonApplications Application Module
Set up the default locale at configuration level! See #61 of module.config.php
from ZendSkeletonApplications Application Module
'translator' => array(
'locale' => 'en_US',
)
这篇关于Zend框架2:如何设置全局语言环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文