From 36bbd5e454b7c91a513bdab8e1947fb2b961d150 Mon Sep 17 00:00:00 2001 From: Adrian Date: Mon, 10 May 2021 15:30:13 +0300 Subject: [PATCH] Firing event when a translation variable has been modified --- src/Events/UpdatedTranslations.php | 36 +++++++++++++++++++ src/Http/Controllers/LanguageController.php | 2 ++ .../LanguageTranslationController.php | 5 +++ src/TranslationServiceProvider.php | 1 + 4 files changed, 44 insertions(+) create mode 100644 src/Events/UpdatedTranslations.php diff --git a/src/Events/UpdatedTranslations.php b/src/Events/UpdatedTranslations.php new file mode 100644 index 0000000..ca3debf --- /dev/null +++ b/src/Events/UpdatedTranslations.php @@ -0,0 +1,36 @@ +translation->addLanguage($request->locale, $request->name); return redirect() diff --git a/src/Http/Controllers/LanguageTranslationController.php b/src/Http/Controllers/LanguageTranslationController.php index 7ad706b..e17f84b 100644 --- a/src/Http/Controllers/LanguageTranslationController.php +++ b/src/Http/Controllers/LanguageTranslationController.php @@ -2,6 +2,7 @@ namespace JoeDixon\Translation\Http\Controllers; +use App\Events\UpdatedTranslations; use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Illuminate\Support\Collection; @@ -56,8 +57,10 @@ public function store(TranslationRequest $request, $language) if ($request->filled('group')) { $namespace = $request->has('namespace') && $request->get('namespace') ? "{$request->get('namespace')}::" : ''; $this->translation->addGroupTranslation($language, "{$namespace}{$request->get('group')}", $request->get('key'), $request->get('value') ?: ''); + UpdatedTranslations::dispatch(); } else { $this->translation->addSingleTranslation($language, 'single', $request->get('key'), $request->get('value') ?: ''); + UpdatedTranslations::dispatch(); } return redirect() @@ -69,8 +72,10 @@ public function update(Request $request, $language) { if (! Str::contains($request->get('group'), 'single')) { $this->translation->addGroupTranslation($language, $request->get('group'), $request->get('key'), $request->get('value') ?: ''); + UpdatedTranslations::dispatch(); } else { $this->translation->addSingleTranslation($language, $request->get('group'), $request->get('key'), $request->get('value') ?: ''); + UpdatedTranslations::dispatch(); } return ['success' => true]; diff --git a/src/TranslationServiceProvider.php b/src/TranslationServiceProvider.php index c8f90b4..6751367 100644 --- a/src/TranslationServiceProvider.php +++ b/src/TranslationServiceProvider.php @@ -82,6 +82,7 @@ private function registerRoutes() private function publishConfiguration() { $this->publishes([ + __DIR__.'/Events/UpdatedTranslations.php' => base_path('/app/Events/UpdatedTranslations.php'), __DIR__.'/../config/translation.php' => config_path('translation.php'), ], 'config'); }