nette-menu and translations

Ajax
Member | 57
+
0
-

Hello!

I used addon nette-menu. Menu works great, my problem is translations. When I set in menu.neon line translator: true, Nette shows error Service 'menu.default': Reference to missing service of type Nette\Localization\ITranslator. Translations in rest of application works.

Base presenter:

abstract class BasePresenter extends Nette\Application\UI\Presenter
{
    protected $translator;

    public function __construct(){
        $this -> translator = new \App\Locale\Translator;
    }

    public function startup() {
        parent::startup();
        $this->translator->init('cs_CZ', !\Nette\Environment::isProduction());
        $this->template->setTranslator($this->translator);
    }
}

Class translator implements ITRanslator

class Translator implements Nette\Localization\ITranslator
{

...

and menu is created in secured presenter:

class BaseSecuredPresenter extends BasePresenter {

    /** @var \DK\Menu\UI\IControlFactory @inject */
    public $menuFactory;


    /**
     * @return \DK\Menu\UI\Control
     */
    protected function createComponentMenu()
    {
        return $this->menuFactory->create();
    }

    public function startup() {
        parent::startup();
        if (!$this->user->isLoggedIn() && $this->getName() !== "Sign" && $this->getAction() !== 'In') {
            $this->redirect("Sign:in");
        }
    }
}

I'm real noob in Nette, I know, that I'm missing something. Can someone explain me what? Thanks!

Comments

Filip Procházka:

Save time by using Kdyby/Translation, don't write your own if you don't need to :)

5 years ago
David Kudera
Backer | 468
+
+1
-

Hi, it should be enough to register your translator as service in your config.neon

services:

    - App\Locale\Translator

and than also use it in you presenters and other places. Just look in forum or documentation how to inject your services ;-)

Comments

Ajax:

Great! It worked! Thanks!!

5 years ago