Search code examples
zend-frameworkinternationalizationzend-translate

How do i use translate in the Controller using Zend?


Usually i user translation in View with this code :

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

How do i get a translation in the Controller?


Solution

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