2021-06-26 17:23:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Http\Middleware;
|
2017-01-15 17:27:24 +01:00
|
|
|
|
2023-09-17 14:29:06 +02:00
|
|
|
use BookStack\Translation\LocaleManager;
|
2017-01-15 17:27:24 +01:00
|
|
|
use Closure;
|
|
|
|
|
|
|
|
class Localization
|
|
|
|
{
|
2023-09-17 14:29:06 +02:00
|
|
|
public function __construct(
|
|
|
|
protected LocaleManager $localeManager
|
|
|
|
) {
|
2022-09-02 20:19:01 +02:00
|
|
|
}
|
2019-01-19 13:11:18 +01:00
|
|
|
|
2017-01-15 17:27:24 +01:00
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
2021-06-26 17:23:15 +02:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
|
|
|
*
|
2017-01-15 17:27:24 +01:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
2023-09-17 14:29:06 +02:00
|
|
|
// Share details of the user's locale for use in views
|
|
|
|
$userLocale = $this->localeManager->getForUser(user());
|
|
|
|
view()->share('locale', $userLocale);
|
2018-09-22 14:18:26 +02:00
|
|
|
|
2023-09-17 14:29:06 +02:00
|
|
|
// Set locale for system components
|
2023-09-17 23:02:12 +02:00
|
|
|
app()->setLocale($userLocale->appLocale());
|
2021-06-26 17:23:15 +02:00
|
|
|
|
2017-01-15 17:27:24 +01:00
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|