BookStack/app/Http/Middleware/Localization.php

35 lines
769 B
PHP
Raw Normal View History

2021-06-26 23:23:15 +08:00
<?php
namespace BookStack\Http\Middleware;
use BookStack\Translation\LocaleManager;
use Closure;
class Localization
{
public function __construct(
protected LocaleManager $localeManager
) {
}
/**
* Handle an incoming request.
*
2021-06-26 23:23:15 +08:00
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
// Share details of the user's locale for use in views
$userLocale = $this->localeManager->getForUser(user());
view()->share('locale', $userLocale);
// Set locale for system components
$this->localeManager->setAppLocale($userLocale);
2021-06-26 23:23:15 +08:00
return $next($request);
}
}