Don't overwrite the Translator class anymore

parent 602b6ab2
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Modules\Translation\Providers; namespace Modules\Translation\Providers;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Modules\Core\Composers\CurrentUserViewComposer; use Modules\Core\Composers\CurrentUserViewComposer;
...@@ -14,8 +15,6 @@ use Modules\Translation\Repositories\File\FileTranslationRepository as FileDiskT ...@@ -14,8 +15,6 @@ use Modules\Translation\Repositories\File\FileTranslationRepository as FileDiskT
use Modules\Translation\Repositories\FileTranslationRepository; use Modules\Translation\Repositories\FileTranslationRepository;
use Modules\Translation\Repositories\TranslationRepository; use Modules\Translation\Repositories\TranslationRepository;
use Modules\Translation\Services\TranslationLoader; use Modules\Translation\Services\TranslationLoader;
use Modules\Translation\Services\Translator;
use Schema;
class TranslationServiceProvider extends ServiceProvider class TranslationServiceProvider extends ServiceProvider
{ {
...@@ -111,9 +110,6 @@ class TranslationServiceProvider extends ServiceProvider ...@@ -111,9 +110,6 @@ class TranslationServiceProvider extends ServiceProvider
protected function registerCustomTranslator() protected function registerCustomTranslator()
{ {
$this->app->offsetUnset('translation.loader');
$this->app->offsetUnset('translator');
$this->app->singleton('translation.loader', function ($app) { $this->app->singleton('translation.loader', function ($app) {
return new TranslationLoader($app['files'], $app['path.lang']); return new TranslationLoader($app['files'], $app['path.lang']);
}); });
...@@ -122,7 +118,7 @@ class TranslationServiceProvider extends ServiceProvider ...@@ -122,7 +118,7 @@ class TranslationServiceProvider extends ServiceProvider
$locale = $app['config']['app.locale']; $locale = $app['config']['app.locale'];
$trans = new Translator($loader, $locale); $trans = new \Illuminate\Translation\Translator($loader, $locale);
$trans->setFallback($app['config']['app.fallback_locale']); $trans->setFallback($app['config']['app.fallback_locale']);
......
<?php
namespace Modules\Translation\Services;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Modules\Translation\Repositories\TranslationRepository;
class Translator extends \Illuminate\Translation\Translator
{
use DispatchesJobs;
/**
* Get the translation for the given key.
*
* @param string $key
* @param array $replace
* @param string $locale
* @param bool $fallback
* @return string
*/
public function get($key, array $replace = [], $locale = null, $fallback = true)
{
$translationRepository = app(TranslationRepository::class);
if ($translation = $translationRepository->findByKeyAndLocale($key, $locale)) {
return $this->makeReplacements($translation, $replace);
}
return parent::get($key, $replace, $locale);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment