The resources/lang
folder contains localization files. The file name corresponds to the view that it will be used. In order to get a value from this file, you can simply use the following code:
`Lang::geConfig;
use Session;
class Locale
{
/**
* Handle an incoming request.
*
* @param IlluminateHttpRequest $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
//$raw_locale = Session::get('locale');
$raw_locale = $request->session()->get('locale');
if (in_array($raw_locale, Config::get('app.locales'))) {
$locale = $raw_locale;
}
else $locale = Config::get('app.locale');
App::setLocale($locale);
return $next($request);
}
}
In app/Http/Kernel.php
in $middlewareGroups=[ ... ]
add the following line:
AppHttpMiddlewareLocale::class,
In routes/web.php
add:
Route::get('setlocale/{locale}', function ($locale) {
if (in_array($locale, Config::get('app.locales'))) {
session(['locale' => $locale]);
}
return redirect()->back();
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…