Simple translator.
Simple and lightweight translator for Nette Framework, providing localization support using NEON translation files., (*1)
composer require drago-ex/translator
Register the Drago\Localization\DI\TranslatorExtension
in your Nette project by adding the following
configuration to your neon
file:, (*3)
extensions: - Drago\Localization\DI\TranslatorExtension(translateDir: %appDir%/locale)
To use the translator in your presenter, add the TranslatorAdapter
trait:, (*4)
use Drago\Localization\TranslatorAdapter
You can access the currently set language using the following property:, (*5)
$this->lang;
To get the translator instance, use the getTranslator
method:, (*6)
$this->getTranslator();
Translation files should be written in the NEON format. For example:, (*7)
"Hello, world!": "Hello, world!"
You can translate strings directly in your Latte templates using the following syntax:, (*8)
{_"Hello, world!"} {* Using a filter for translation *} {$var|translate}
To use translations in forms, simply set the translator for the form:, (*9)
$form->setTranslator($this->getTranslator());
Set up your routes to support language prefixes. For example, you can define routes with language codes:, (*10)
$router->addRoute('[<lang=en cs|en>/]<presenter>/<action>', 'Presenter:action');
To switch between languages in your templates, you can use n:href to pass the selected language:, (*11)
<a n:href="this, 'lang' => 'cs'">Czech</a> <a n:href="this, 'lang' => 'en'">English</a>