The next development that we are going to carry out is to use a middleware to detect the language configured by the user and establish it through the translation text strings, in addition, we also define the acronyms or language tag in the URL to return the corresponding translation.
The next development that we are going to carry out is to use a middleware to detect the language configured by the user and establish it using the translation text strings that we defined before, in addition, we also define the acronym or language label in the URL to return the translation accordingly. ; for it:
function routeBlog() {
Route::get('', [BlogController::class, 'index'])->name('blog.index');
Route::get('detail/{id}', [BlogController::class, 'show'])->name('blog.show');
}
Route::group(['prefix' => '{locale}/blog','middleware' => LanguagePrefixMiddleware::class], function () {
routeBlog();
});
Route::group(['prefix' => 'blog','middleware' => LanguagePrefixMiddleware::class], function () {
function () {
routeBlog();
});
As you can see, we created a routeBlog() function to group the routes to which we want to verify the use of the language, in this example, those of the blog, so that it can be consumed through locale:
es/blog/*
en/blog/*
And without the locale, and in this case, it is redirected to the Spanish language according to the redirection defined in the middleware:
🔴
The next development that we are going to carry out is to use a middleware to detect the language configured by the user and establish it through the translation text strings, in addition, we also define the acronyms or language tag in the URL to return the corresponding translation.