mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-15 01:54:09 -08:00
eed253bd2f
Signed-off-by: snipe <snipe@snipe.net>
52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Models\Setting;
|
|
use Closure;
|
|
use \App\Helpers\Helper;
|
|
use Illuminate\Support\Facades\Log;
|
|
class CheckLocale
|
|
{
|
|
private function warn_legacy_locale($language, $source)
|
|
{
|
|
if ($language != Helper::mapLegacyLocale($language)) {
|
|
Log::warning("$source $language and should be updated to be ".Helper::mapLegacyLocale($language));
|
|
}
|
|
}
|
|
/**
|
|
* Handle the locale for the user, default to settings otherwise.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \Closure $next
|
|
* @param string|null $guard
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle($request, Closure $next, $guard = null)
|
|
{
|
|
|
|
// Default app settings from config
|
|
$language = config('app.locale');
|
|
$this->warn_legacy_locale($language, "APP_LOCALE in .env is set to");
|
|
|
|
if ($settings = Setting::getSettings()) {
|
|
|
|
// User's preference
|
|
if (($request->user()) && ($request->user()->locale)) {
|
|
$language = $request->user()->locale;
|
|
$this->warn_legacy_locale($language, "username ".$request->user()->username." (".$request->user()->id.") has a language");
|
|
|
|
// App setting preference
|
|
} elseif ($settings->locale != '') {
|
|
$language = $settings->locale;
|
|
$this->warn_legacy_locale($language, "App Settings is set to");
|
|
}
|
|
|
|
}
|
|
|
|
app()->setLocale(Helper::mapLegacyLocale($language));
|
|
return $next($request);
|
|
}
|
|
}
|