Need help with translating routes
Hello to all,
need help, im beginner in this and i am trying to translate my routes
Web.php,
Route::prefix('{locale}') ->where(['locale' => '[a-zA-Z]{2}']) ->middleware('SetLocale') ->group(function () {
Route::view('/', 'welcome', ['name' => ("welcome")]);
Route::view('/sluzby', 'sluzby', ['name' => ('sluzby')]);
Route::view('/harmonogram', 'harmonogram', ['name' => 'harmonogram']);
Route::view('/kontakt', 'kontakt', ['name' => 'kontakt']);
Route::view('/gdpr', 'gdpr', ['name' => 'gdpr']);
Route::view('/dashboard', 'dashboard', ['name' => 'dashboard']);
});
Route::get('/', function () {
return redirect(app()->getLocale());
});
SetLocale middleware:
class SetLocale { public function handle(Request $request, Closure $next) { $locale = $request->segment(1);
if (empty($locale)) {
$locale = config('app.locale');
};
// dd($locale);
App::setLocale($locale);
URL::defaults(['app.locale' => $locale]);
return $next($request);
}
}
bootstrap/app.php
return Application::configure(basePath: dirname(DIR)) ->withRouting( web: DIR.'/../routes/web.php', commands: DIR.'/../routes/console.php', health: '/up', ) ->withMiddleware(function (Middleware $middleware) {
$middleware->web(append: [
SetLocale::class,
]);
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
config/app.php:
'locale' => 'cs',
'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),
'faker_locale' => env('APP_FAKER_LOCALE', 'en_US'),
'available_locales' => [
'cs',
'en',
],
I also published lang folder with cs and en folders that contain paths.php and general.php, where i have the translations.
And it's giving this error setlocale(): Argument #1 ($category) must be of type int, Illuminate\Http\Request given
Many thanks for help.
Please or to participate in this conversation.