PHP code example of vladahejda / nettesimpletranslator
1. Go to this page and download the library: Download vladahejda/nettesimpletranslator 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 / nettesimpletranslator example snippets
class BasePresenter extends \Nette\Application\UI\Presenter
{
/** @var string @persistent */
public $language = 'en';
/** @var \NetteSimpleTranslator\Translator */
protected $translator;
public function injectTranslator(\NetteSimpleTranslator\Translator $translator)
{
$this->translator = $translator;
}
public function startup()
{
parent::startup();
$this->translator->setCurrentLanguage($this->language);
}
protected function createTemplate()
{
$template = parent::createTemplate();
$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;
}
}