Extension from Nette\Localization
Required:
composer require chomenko/translator
In base config.neon:
translator:
localDir: %appDir%/Localization
defaultLang: cs
#pattern: '/%+([a-z0-9]+)/u' #old pattern style %value, new style is {{ value }}
extensions:
translator: Chomenko\Translator\DI\TranslatorExtension
In base presenter:
<?php
namespace App\Presenters;
use Nette\Application\UI\Presenter;
use Chomenko\Translator\Translate;
class BasePresenter extends Presenter
{
/**
* Install Translator
*/
use Translate;
public function startup() {
parent::startup();
$config = $this->translator->getConfig();
$this->template->setTranslator($this->translator);
}
}
In latte:
{_"name", ["Jméno"]} {*Default value. Used if value is not stored*}
{_"Name is: {{ name }}", ["name" => "Franta"]}
{_"Birthdate: {{ date }}", 1991}
Use only in the developer mode. Do not use for production!!
The translation modal can be invoked by pressing CTRL + ALT + mouse CLICK translate item
. Translating elements turn red
Modal is required Bootstrap and JQuery. If you are developing on Unix you will need to set the right to write
In presenter:
<?php
$config = $this->translator->getConfig();
$config->translateModalEnable();
In @layout.latte:
{control translateModal}