How can I prolong laravel translation (any other component)?

I want to implement some additional functionality for Illuminate\Translate\Translator

.

So, I create my folder in a directory ~/vendor

, put the My/Traslator

class there that will implement Symfony\Component\Translation\TranslatorInterface

. Right?

Is it possible to extend the laravel translator class (a lot of functionality would be duplicated otherwise) in my package?

If everything is ok, it will need to bind to the current version of laravel to keep the code stable. But what happens if the enduser version of laravel is different than what is required in my package?

What should I do to get laravel to use my translator class in the application (facades, etc.)?

+3


source to share


1 answer


This page has more information: http://laravel.com/docs/5.0/extending#container-based-extension

So what you need to do:



  • Extending a built-in class from the vendor catalog
  • Create a new service provider that will add your broadcast class to the service container
  • Replace your Laravels translation provider in config / app.php with your translation provider's namespace.

Now, when you request a translation service provider from a service container - either directly ( app('translator')

) or a facade Lang

, it will return your translation class, not Laravels.

+3


source







All Articles