Gettext Translator is tool that enables simple and user friendly translation of your texts via panel in debug bar. No need to edit or operate with .po/.mo files.
Tested with nette 2.1>, please report any bugs into Issues
{
"require":{
"salamek/gettexttranslator"
}
}
common:
gettextTranslator:
lang: cs #default language
files:
front: %appDir%/lang # for module Front and other non-specified modules
admin: %appDir%/lang-admin # for module Admin
# optional with defaults
layout: horizontal # or: vertical
height: 450
extensions:
gettextTranslator: GettextTranslator\DI\Extension
class BasePresenter extends Nette\Application\UI\Presenter
{
/** @persistent */
public $lang;
/** @var \GettextTranslator\Gettext */
protected $translator;
/**
* @param \GettextTranslator\Gettext
*/
public function injectTranslator(GettextTranslator\Gettext $translator)
{
$this->translator = $translator;
}
public function createTemplate($class = NULL)
{
$template = parent::createTemplate($class);
// if not set, the default language will be used
if (!isset($this->lang))
{
$this->lang = $this->translator->getLang();
}
else
{
$this->translator->setLang($this->lang);
}
$template->setTranslator($this->translator);
return $template;
}
}
Choose language:
<a n:href="this, lang => en">English</a>
<a n:href="this, lang => cs">Česky</a>
{_"Login"}
{_"piece", $number}
1 piece <!-- $number = 1; -->
2 pieces <!-- $number = 2; -->
5 pieces <!-- $number = 5; -->
protected function createComponentMyForm()
{
$form = new Form;
$form->setTranslator($this->translator);
// ...
return $form;
}
public function createTemplate($class = NULL)
{
$template = parent::createTemplate($class);
$template->setTranslator($this->parent->translator); // $translator in presenter has to be public
// or $this->translator via construct/inject
return $template;
}
<div n:foreach="$flashes AS $flash" class="alert {$flash->type} fade in">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
{_$flash->message|noescape}
</div>
- Adam Schubert
- Josef Kufner (jk@frozen-doe.net)
- Miroslav Paulík (https://github.com/castamir)
- Roman Sklenář (http://romansklenar.cz)
- Miroslav Smetana
- Jan Smitka
- Patrik Votoček (patrik@votocek.cz)
- Tomáš Votruba (tomas.vot@gmail.com)
- Václav Vrbka (gmvasek@php-info.cz)
Under New BSD License