Issues

ZF-2763: Zend_View_Helper_Translate getLocale() and setLocale() fatal error

Issue Type: Bug Created: 2008-02-29T09:29:05.000+0000 Last Updated: 2008-03-21T17:05:31.000+0000 Status: Resolved Fix version(s): - 1.5.0 (17/Mar/08)

Reporter: Emanuele Deserti (lord_lele) Assignee: Thomas Weidner (thomas) Tags: - Zend_View

Related issues: Attachments:

Description

Directly from the manual:

<pre class="highlight">
<?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:

<pre class="highlight">
<?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:

<pre class="highlight">
<?php
require_once 'Zend/Registry.php';
require_once 'Zend/Translate.php';
require_once 'Zend/View.php';

$adapter = new Zend_Translate('array', array('simple' => 'einfach'), 'de');
Zend_Registry::set('Zend_Translate', $adapter);

$view = new Zend_View();
echo $view->translate()->getLocale();

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:

<pre class="highlight">
if (null === $messageid) {
    return $this;
}

if (null === ($translate = $this->getTranslator())) {
    return $messageid;
}

And this is the code from the 1.5.0 version

<pre class="highlight">
if ($this->translate === null) {
    require_once 'Zend/Registry.php';
    if (!Zend_Registry::isRegistered('Zend_Translate')) {
        if (empty($messageid)) {
            return $this;
        } else {
            return $messageid;
        }
    } else {
        $this->translate = Zend_Registry::get('Zend_Translate');
    }
}

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.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts