BookStack/app/Http/Middleware/Localization.php
Dan Brown ac9a65945f
Locales: Performed cleanup and alignment of locale handling
- Reduced app settings down to what's required.
- Used new view-shared $locale object instead of using globals via
  config.
- Aligned language used to default on "locale" instead of mixing
  locale/language.

For #4501
2023-09-17 13:31:38 +01:00

35 lines
769 B
PHP

<?php
namespace BookStack\Http\Middleware;
use BookStack\Translation\LocaleManager;
use Closure;
class Localization
{
public function __construct(
protected LocaleManager $localeManager
) {
}
/**
* Handle an incoming request.
*
* @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);
return $next($request);
}
}