From 391f053d8b23d11e54172edd3265eafe2c1ec4e7 Mon Sep 17 00:00:00 2001 From: Tarvo Reinpalu Date: Thu, 22 Oct 2020 11:32:38 +0300 Subject: [PATCH] Load translations during ServingNova event --- src/NovaTranslationsLoader.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/NovaTranslationsLoader.php b/src/NovaTranslationsLoader.php index 6291746..56679d4 100644 --- a/src/NovaTranslationsLoader.php +++ b/src/NovaTranslationsLoader.php @@ -3,6 +3,7 @@ namespace OptimistDigital\NovaTranslationsLoader; use Laravel\Nova\Nova; +use Laravel\Nova\Events\ServingNova; use Illuminate\Support\Facades\File; use Illuminate\Support\ServiceProvider; @@ -45,14 +46,16 @@ protected function translations() } if (method_exists('Nova', 'translations')) { - $locale = app()->getLocale(); - $fallbackLocale = config('app.fallback_locale'); + Nova::serving(function (ServingNova $event) { + $locale = app()->getLocale(); + $fallbackLocale = config('app.fallback_locale'); - if ($this->attemptToLoadTranslations($locale, 'project')) return; - if ($this->attemptToLoadTranslations($locale, 'local')) return; - if ($this->attemptToLoadTranslations($fallbackLocale, 'project')) return; - if ($this->attemptToLoadTranslations($fallbackLocale, 'local')) return; - $this->attemptToLoadTranslations('en', 'local'); + if ($this->attemptToLoadTranslations($locale, 'project')) return; + if ($this->attemptToLoadTranslations($locale, 'local')) return; + if ($this->attemptToLoadTranslations($fallbackLocale, 'project')) return; + if ($this->attemptToLoadTranslations($fallbackLocale, 'local')) return; + $this->attemptToLoadTranslations('en', 'local'); + }); } }