/** * Add gettext helpers to template. * * @param Template * @param ITranslator */ public static function registerHelpers(Template $template, ITranslator $translator) { $template->registerHelper('gettext', array($translator, 'gettext')); $template->registerHelper('ngettext', array($translator, 'ngettext')); $template->registerHelper('pgettext', array($translator, 'pgettext')); $template->registerHelper('npgettext', array($translator, 'npgettext')); }
/** * @param Latte\Template|\Nette\Bridges\ApplicationLatte\Template|\Nette\Templating\Template $template * @param ITranslator $translator */ private static function overrideTemplateTranslator($template, ITranslator $translator) { if ($template instanceof Latte\Template) { $template->getEngine()->addFilter('translate', array(new TemplateHelpers($translator), 'translate')); } elseif ($template instanceof \Nette\Bridges\ApplicationLatte\Template) { $template->getLatte()->addFilter('translate', array(new TemplateHelpers($translator), 'translate')); } elseif ($template instanceof \Nette\Templating\Template) { $template->registerHelper('translate', array(new TemplateHelpers($translator), 'translate')); } return $translator; }
/** * create helper to template */ public function registerAsHelper(Template $template) { $template->registerHelper('currency', callback($this, 'format')); $template->registerHelper('currencyTo', callback($this, 'formatTo')); $template->bank = $this; }