1. Go to this page and download the library: Download vladahejda/livetranslator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vladahejda / livetranslator example snippets
class BasePresenter extends \Nette\Application\UI\Presenter
{
/** @var string @persistent */
public $lang = 'en';
/** @var \LiveTranslator\Translator @inject */
public $translator;
// since Nette 2.1 you can omit this method
public function injectTranslator(\LiveTranslator\Translator $translator)
{
$this->translator = $translator;
}
public function startup()
{
parent::startup();
$this->translator->setCurrentLang($this->lang);
}
protected function createTemplate($class = NULL)
{
$template = parent::createTemplate($class);
$template->setTranslator($this->translator);
return $template;
}
// to have translated even forms add this method too
protected function createComponent($name)
{
$component = parent::createComponent($name);
if ($component instanceof \Nette\Forms\Form) {
$component->setTranslator($this->translator);
}
return $component;
}
}