Skip to content

Commit

Permalink
Load translations during ServingNova event
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarpsvo committed Oct 22, 2020
1 parent 7121b70 commit 391f053
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/NovaTranslationsLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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');
});
}
}

Expand Down

0 comments on commit 391f053

Please sign in to comment.