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