Professional Documents
Culture Documents
Laravel Localizaton
Laravel Localizaton
लारवेल लोकललज़टन
Локализация Laravel
లారావెల్ స్థానికీకరణ
Akash Pundir
Localization
<?php
return [
'welcome' => 'आप कैसे हैं?'
];
?>
In resources folder make
lang/fr/messages.php
<?php
return [
'welcome'=>'Comment vas-tu?'
];
?>
In Web.php, let’s make a route for it
Route::get('/{lang?}', function () {
return view('welcome');
});
Do you remember how to make middleware?
'web' => [
\App\Http\Middleware\SetLocale::class,
],
Now, let’s pass our request through
middleware before returning view
public function handle(Request $request, Closure $next): Response
{
$locale = $request->segment(1); // Get the first URL segment as
the locale
return $next($request);
}
In welcome.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Laravel Localization</title>
</head>
<body>
<h1>{{ trans('messages.welcome') }}</h1>
</body>
</html>
Basic Artisan Command to clear cache of
routes