How do i use translate in the Controller using Zend?
Asked Answered
Z

3

7

Usually i user translation in View with this code :

<?php echo $this->translate("hello"); ?>

How do i get a translation in the Controller?

Zirconia answered 24/6, 2011 at 23:11 Comment(0)
D
5

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.

Darlinedarling answered 24/6, 2011 at 23:56 Comment(0)
S
21

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).

Sheepdip answered 25/6, 2011 at 0:6 Comment(0)
D
5

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.

Darlinedarling answered 24/6, 2011 at 23:56 Comment(0)
C
0

Or using the service locator (ZF2):

$translator = $this->getServiceLocator()->get('translator');
$feed->setTitle($translator->translate('My RSS Feed'));
Candiecandied answered 13/6, 2019 at 8:55 Comment(1)
please add an explanation to your answer.Pellmell

© 2022 - 2024 — McMap. All rights reserved.