Skip to content

Instantly share code, notes, and snippets.

@msonowal
Created June 20, 2018 07:23
Show Gist options
  • Select an option

  • Save msonowal/1918eec78c69ddeea74035a94ca8cebb to your computer and use it in GitHub Desktop.

Select an option

Save msonowal/1918eec78c69ddeea74035a94ca8cebb to your computer and use it in GitHub Desktop.
Route::get('/js/lang.js', function () {
Cache::forget('lang.js');
$strings = Cache::rememberForever('lang.js', function () {
$lang = config('app.locale');
$files = glob(resource_path('lang/' . $lang . '/*.php'));
$strings = [];
foreach ($files as $file) {
$name = basename($file, '.php');
$strings[$name] = require $file;
}
return $strings;
});
$javascript = 'window.i18n = ' . json_encode($strings) . ';';
return response($javascript, 200, ['Content-Type' => 'text/javascript']);
})->name('assets.lang');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment