GettextTranslator 2.0.6 with Nette 2.0.1 non-member function setLang()

Notice: This thread is very old.
pseudonym
Member | 57
+
0
-

Hi,
I'm having trouble with corect configuration of GettextTranslator extension.

I'm following instructions on this page https://addons2.nette.org/…xttranslator but when I copy code snippets to BasePresenter the DebugPanel raise Fatal Error:

Call to a member function setLang() on a non-object

21:        }
22:
23:        protected function startup()
24:        {
25:            parent::startup();
26:
27:            if ($this->lang == NULL) {
28:                $this->lang = $this->translator->getLang();
29:            }
30:
31:            $this->translator->setLang($this->lang); // this line raises error
32:
33:        }

This error is pretty logical because variable $this->translator not object. I hope that there is quick fix to this problem. If you can please help me. Thanks in advance.

BasePresenter.php:

<?php

abstract class BasePresenter extends Nette\Application\UI\Presenter
{
    /** @persistent */
    public $lang;

    /** @var GettextTranslator\Gettext */
    protected $translator;

    /**
     * @param GettextTranslator\Gettext
     */
    public function injectTranslator(GettextTranslator\Gettext $translator)
    {
        $this->translator = $translator;
    }

    protected function startup()
    {
        parent::startup();

        if ($this->lang == NULL) {
            $this->lang = $this->translator->getLang();
        }

        $this->translator->setLang($this->lang);
    }

    public function createTemplate($class = NULL)
    {
        $template = parent::createTemplate($class);
        $template->setTranslator($this->translator);

        return $template;
    }
}

Edit:

Now I see where the problem is. In the Nette version of 2.0.1 the Inject Autowire is not supported (https://pla.nette.org/…ect-autowire) since Nette supports Inject Autowire from version 2.0.5.

You can still help me if you want… Do you have someone experience with changing Nette version from 2.0.1 to 2.0.5 or even better to 2.0.12? Or maybe there is another way to inject translator. Can you help me?

Last edited by pseudonym (2013-09-09 02:46)

pseudonym
Member | 57
+
0
-

Sorry for unnecessary topic, I solved it on my own.

For migration from Nette 2.0.1 to Nette 2.0.5 I just change library files and everything is working fine + Injection Autowiring works so Gettext Translator too.

The moderator can close this topic. Thanks.