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
-
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 donew CustomTranslator()
without having to pass in a callback themselves. Like below. Unfortunately, this is currently impossible asTranslatorExtension
is 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|translate
filter.Beta Was this translation helpful? Give feedback.
All reactions