-- Mauricio Cuenca <[EMAIL PROTECTED]> wrote
(on Tuesday, 04 March 2008, 08:53 AM -0800):
> I am implementing Zend_Translate in an application, but right now, I have
> initialize the object in each controller using the init() method. Is it
> possible to create a Zend_Translate object to be available in all the views?
> 
> Should I create a instance of it in the bootstrap file? What would be the
> simplest approach?
> 
> I have something like this in each init():
> 
>       $translate = new Zend_Translate('csv', LANG_EN);
>       $this->view->translate = $translate;

All Zend_Translate-aware classes, including the translate view helper
(which you should be using, instead of setting the translate view
property), will look for a translate object in Zend_Registry registered
as 'Zend_Translate' -- so the easiest method is to instantiate once and
place it in the registry:
    
    $translate = new Zend_Translate('csv', LANG_EN);
    Zend_Registry::set('Zend_Translate', $translate);

Place that in your bootstrap, and you should be in good shape. If you
need access to the object, you can grab it from the registry:

    $translate = Zend_Registry::get('Zend_Translate');

    // or operate on it directly:
    $translation = Zend_Registry::get('Zend_Translate')->translate($string);

-- 
Matthew Weier O'Phinney
PHP Developer            | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to