laravel-learn-bbs/app/Http/Middleware/ChangeLocale.php

26 lines
551 B
PHP
Raw Permalink Normal View History

2018-06-16 01:15:01 +00:00
<?php
namespace App\Http\Middleware;
use Closure;
class ChangeLocale
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$language = $request->header('accept-language');
if ($language) {
preg_match('/^([A-Za-z-]+),?/', $language, $matches);
\App::setLocale($matches ? $matches[1] : 'zh-CN');
}
return $next($request);
}
}