Just fyi a small correction for your code,

If you are initiating Zend_Translate using single files and not the automatic you should always set a locale.
$translate = new Zend_Translate('csv', '/path/to/translation.csv', 'en');

Greetings
Thomas Weidner, I18N Team Leader
http://www.thomasweidner.com

----- Original Message ----- From: "Mauricio Cuenca" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, March 04, 2008 6:36 PM
Subject: Re: [fw-general] Zend_Translator globally available



Hello Matthew,

Thanks for your help. I initialzed the object using the Zend_Registry in the
boostrap this way:

$translate = new Zend_Translate('csv', '/path/to/translation.csv');
Zend_Registry::set('Zend_Translate', $translate);

An then, using the helper, the only thing that you need to do in the views
is:

echo $this->translate("Hello world!");

It's really simple. I posted my solution because maybe it can help someone
else.



Matthew Weier O'Phinney-3 wrote:

-- 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/



--
View this message in context: http://www.nabble.com/Zend_Translator-global-availabilty-tp15831648s16154p15832705.html Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to