Replies: 1 comment 1 reply
-
|
This is not an optimal use of inheritance. It is better to use either composition or, better yet, factory: class CustomTranslatorFactory
{
public static function create() {
return new Latte\TranslatorExtension([self::class, 'translate']);
}
public static function translate($key, $data = null, $lang = null) {
return app()->translate($key, $data, $lang);
}
}
$latte->addExtension(CustomTranslatorFactory::create()); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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.Beta Was this translation helpful? Give feedback.
All reactions