1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-02-24 15:27:43 +01:00
openstamanager/app/Http/Middleware/HandleInertiaRequests.php
Maicol Battistini ceb854bbb3
feat(i18n): Aggiunto nuovo sistema di traduzioni backend e frontend
Il nuovo sistema si basa sul sistema nativo di Laravel. Le traduzioni e la lingua dell'utente vengono passati a JS (mithril) tramite Inertia. C'è anche una route per modificare la lingua.
2021-08-03 19:17:43 +02:00

53 lines
1.3 KiB
PHP

<?php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Inertia\Middleware;
use Nette\Utils\Json;
class HandleInertiaRequests extends Middleware
{
/**
* The root template that's loaded on the first page visit.
*
* @see https://inertiajs.com/server-side-setup#root-template
* @var string
*/
protected $rootView = 'app';
/**
* Determines the current asset version.
*
* @see https://inertiajs.com/asset-versioning
* @param \Illuminate\Http\Request $request
* @return string|null
*/
public function version(Request $request)
{
return parent::version($request);
}
/**
* Defines the props that are shared by default.
*
* @see https://inertiajs.com/shared-data
* @param \Illuminate\Http\Request $request
* @return array
*/
public function share(Request $request)
{
return array_merge(parent::share($request), [
'locale' => fn () => app()->getLocale(),
'translations' => function () {
$json = resource_path('lang/'.app()->getLocale().'.json');
if (!file_exists($json)) {
return [];
}
return Json::decode(file_get_contents($json));
},
]);
}
}