Created
January 19, 2021 12:01
-
-
Save johanvanhelden/7d9d3f2d33c1f7fafb4be13d01b150c6 to your computer and use it in GitHub Desktop.
Revisions
-
johanvanhelden created this gist
Jan 19, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ <?php declare(strict_types=1); use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Route; // Localization Route::get('/js/lang-messages.js', function (): void { $lang = config('app.locale'); $cacheKey = $lang . '.lang-messages.js'; if (App::environment('local', 'testing')) { Cache::forget($cacheKey); } $strings = Cache::rememberForever($cacheKey, function () use ($lang) { $files = glob(resource_path('lang/' . $lang . '/*.php')); $strings = []; foreach ($files as $file) { $name = basename($file, '.php'); $strings[$lang . '.' . $name] = require $file; } return $strings; }); header('Content-Type: text/javascript'); echo 'window.i18n = ' . json_encode($strings) . ';'; exit(); });