drago-ex / translator
Simple translator for Nette Framework
Installs: 2 004
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=8.1 <8.4
- nette/application: ^3.1
- nette/di: ^3.1
- nette/utils: ^4.0
Requires (Dev)
- nette/bootstrap: ^3.1
- nette/tester: ^2.5
- phpstan/phpstan-nette: ^1.2.9
- tracy/tracy: ^2.10
README
Simple translator.
Technology
- PHP 8.1 or higher
- composer
Installation
composer require drago-ex/translator
Extension registration
extensions: - Drago\Localization\DI\TranslatorExtension(translateDir: %appDir%/locale)
Use in the presenter
use Drago\Localization\TranslatorAdapter
Currently set language
$this->lang;
A method that returns a translator
$this->getTranslator();
We will create the translation in neon files
"Hello, world!": "Hello, world!"
Translation in the template
{_"Hello, world!"} {* filter for translate *} {$var|translate}
Translation in forms
$form->setTranslator($this->getTranslator());
Route settings for translation
$router->addRoute('[<lang=en cs|en>/]<presenter>/<action>', 'Presenter:action');
Switching languages
<a n:href="this, 'lang' => 'cs'">Czech</a> <a n:href="this, 'lang' => 'en'">English</a>