I have a website in five languages and with all the URLs translated in each language for every page and I am going to update it using Laravel 5.3.
I have followed this tutorial to add the following multilingual locales to my project:
'locales' => ['de' => 'German', 'en' => 'English', 'fr' => 'French', 'it' => 'Italian', 'es' => 'Spanish']
And this could be an example of the Contact Us
page routes in the web.php
file:
Route::get('/kontakt', 'ContactController@index');
Route::get('/contact', 'ContactController@index');
Route::get('/contactez', 'ContactController@index');
Route::get('/contattaci', 'ContactController@index');
Route::get('/contacto', 'ContactController@index');
But if I type in the browser: http://localhost/myproject/en/contattaci
or http://localhost/myproject/en/kontakt
I can access to the Contact view, and this should not happen, just should work contact with the en locale: /en/contact
and contattaci with Italian (/it/contattaci
) and kontakt with German (/de/kontakt
), etc.
Somebody know why is happening this or which is the right way to create the different translated routes?
You probably didn't specify the full route path. Try something like this :
// EN routes
Route::group(['prefix' => 'en'], function() {
Route::get('contact', 'ContactController@index');
//... other EN routes
});
// FR routes
Route::group(['prefix' => 'fr'], function() {
Route::get('contact', 'ContactController@index');
//... other FR routes
});
But you should check @Moppo's link because there are easier ways to manage localized routes.