Explain your intentions
I'd like to extend a custom TranslatorExtension from Latte's built-in one. I mainly need to encapsulate the translator function in a class, so that consumers can just do new CustomTranslator() without having to pass in a callback themselves. Like below. Unfortunately, this is currently impossible as TranslatorExtension is marked as final.
class CustomTranslator extends \Latte\TranslatorExtension
{
public function __construct() {
parent::__construct([$this, 'translate']);
}
public function translate($key, $data = null, $lang = null) {
return app()->translate($key, $data, $lang);
}
}
Make a strong case of the merits of this feature
I'm assuming there's no specific reason the class can't be extendable. If one wanted to do this, one would have to re-implement all the useful features inside it, like the _ tag and the |translate filter.
Explain your intentions
I'd like to extend a custom
TranslatorExtensionfrom Latte's built-in one. I mainly need to encapsulate the translator function in a class, so that consumers can just donew CustomTranslator()without having to pass in a callback themselves. Like below. Unfortunately, this is currently impossible asTranslatorExtensionis marked asfinal.Make a strong case of the merits of this feature
I'm assuming there's no specific reason the class can't be extendable. If one wanted to do this, one would have to re-implement all the useful features inside it, like the
_tag and the|translatefilter.