我使用laravel语言english和bangla。几天前它运行良好,但现在它不起作用。这是我的app.php。
<?php
return [
'name' => 'Laravel',
'env' => env('APP_ENV', 'production'),
'debug' => env('APP_DEBUG', false),
'url' => env('APP_URL', 'http://localhost'),
'timezone' => 'UTC',
'locale' => 'bl',
'fallback_locale' => 'en',
'key' => env('APP_KEY'),
'cipher' => 'AES-256-CBC',
?>
答案 0 :(得分:0)
我写了一个非常简单的中间件来设置浏览器的语言:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Request;
class Language
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
App::setLocale(explode('-', explode(',', Request::server('HTTP_ACCEPT_LANGUAGE'))[0])[0]);
return $next($request);
}
}
并在Kernel.php中注册:
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\Language::class,
\App\Http\Middleware\TrustProxies::class,
如果您希望用户更改语言,请参见Laravel localization