我正在Laravel建立一个网站, 我正在使用浏览器语言并相应地设置网站的语言。
问题是,Registrar.php或English
中似乎没有翻译Dutch中的任何内容有人可以帮帮我吗? 谢谢, G3
答案 0 :(得分:2)
要完成这项工作,您需要使用中间件来设置区域设置:
在LocaleMiddleware.php
目录
app/http/middleware
//LocaleMiddleware.php
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Session\Store as Session;
use Illuminate\Contracts\Auth\Guard as Auth;
class LocaleMiddleware {
public function __construct(Session $session)
{
$this->session = $session;
}
//Languages available in your resources/lang
protected $languages = ['en','es', 'nl-be'];
public function handle($request, Closure $next)
{
$langlist = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
// We just want the main language
$lang = substr($langlist,0,2);
if(isset($this->languages[$lang])){
app()->setLocale($lang);
}else{
//You may log this here
}
return $next($request);
}
}
然后在app\httpe.kernel.php
数组中$middleware
注册中间件
/**
* The application's global HTTP middleware stack.
*
* @var array
*/
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
.........
\App\Http\Middleware\LocaleMiddleware::class,
];
创建lang文件
您需要为要支持的所有语言创建单独的文件夹,并相应地翻译其中的文件,例如nl-be\validation.php
。
您可以首先将resources/lang/en to resources/lang/nl-be, then translate the contents of
nl-be \ validation.php`的内容复制到荷兰语等值