开发者

How do i use translate in the Controller using Zend?

开发者 https://www.devze.com 2023-03-15 19:20 出处:网络
Usually i user translation in View with this code : <?php ec开发者_如何学运维ho $this->translate(\"hello\"); ?>

Usually i user translation in View with this code :

<?php ec开发者_如何学运维ho $this->translate("hello"); ?>

How do i get a translation in the Controller?


To use translation in the controller:

$this->view->translate('Something to translate');

Or create a translation action helper if you want to keep everything clean and pretty (although I don't think it's worth the trouble in this case).


If you're creating the zend_translate object in the bootstrap, you can set it in the Zend_Registry for later use:

Zend_Registry::set('translate', $translate);

and then use it in the controller:

$translate = Zend_Registry::get('translate');
$translate->translate("hello");

As far as I know, Zend_Controller doesn't include built-in support for zend_translate.


Or using the service locator (ZF2):

$translator = $this->getServiceLocator()->get('translator');
$feed->setTitle($translator->translate('My RSS Feed'));
0

精彩评论

暂无评论...
验证码 换一张
取 消