ZF-2763: Zend_View_Helper_Translate getLocale() and setLocale() fatal error
Description
Directly from the manual:
<?php
// our example adapter
$adapter = new Zend_Translate('array', array('simple' => 'einfach'), 'de');
Zend_Registry::set('Zend_Translate', $adapter);
// within your view
echo $this->translate()->getLocale();
?>
this returns a FATAL ERROR: Fatal error: Call to a member function getLocale() on a non-object
Even this:
<?php
// within your view
$adapter = new Zend_Translate('array', array('simple' => 'einfach'), 'de');
$this->translate()->setTranslator($adapter)->translate('simple');
// this returns 'einfach'
?>
returns a FATAL ERROR: Fatal error: Call to a member function setTranslator() on a non-object
Maybe I think because the translate() method, if it find a Zend_Translate object in Registry will not return himself but only the translated string, so getLocale() and setLocale() cannot be executed.
Comments
Posted by Thomas Weidner (thomas) on 2008-02-29T12:14:12.000+0000
If seems that you are using outdated code.
I rewrote the mentioned example that you can use it within one file simulating an extra view:
As you see it's exactly the same as yours but instead of splitting the files to bootstrap and view I made one file. There is no exception returned, but the set locale.
Could it be that you executed the example as it is from one file, without splitting it to bootstrap and view, as mentioned ?
Posted by Thomas Weidner (thomas) on 2008-03-01T16:33:25.000+0000
Issue wring executed... no problem found. You are free to reopen when you have additional informations.
Posted by Emanuele Deserti (lord_lele) on 2008-03-03T03:37:09.000+0000
Well, maybe we have found the problem :-)
This is the code take from snapshot:
And this is the code from the 1.5.0 version
With the code from snapshot, this helper works fine.
Many thanks.
Posted by Wil Sinclair (wil) on 2008-03-21T17:05:31.000+0000
This issue should have been fixed for the 1.5 release.