Support the ongoing development of Laravel.io →
posted 10 years ago
Requests

Hi,

i would like to create a bilingual website, let's say english and french:

http://www.domain.com/en/contact

http://www.domain.com/fr/contact

The site has some pages like contact, products, faq etc. and every page has it's own controller action.

First of all i redirect all / requests to /en:

Route::get('/', function(){Redirect::to('/en');});

After that i would use something like this:

Route::group(array('prefix' => 'en'), function()

  Route::get('/contact', 'MyController@contact');
  Route::get('/products', 'MyController@products');
  Route::get('/faq', 'MyController@faq');

});

Route::group(array('prefix' => 'fr'), function()

  Route::get('/contact', 'MyController@contact');
  Route::get('/products', 'MyController@products');
  Route::get('/faq', 'MyController@faq');

});

But that repeats my code and i don't really like it.

What about this one?

  Route::get('/{language}/contact', 'MyController@contact');
  Route::get('/{language}/products', 'MyController@products');
  Route::get('/{language}/faq', 'MyController@faq');

Another idea would be this:

  Route::get('/{language}/{page}', 'MyController');

But this don't lead directly to the actions but only the controller.

Any ideas?

Thanks, Sharping

Last updated 2 years ago.
0

You want to do multi-lang just for the interface or also the content? I think it's better to do something in views than separate your site by routing. You can set session variables that contains translated words for each languages to display in views.

Last updated 2 years ago.
0

Did you take a look at this: https://github.com/mcamara/laravel-localization ? I had the exact same problem as you and this package helped a lot!

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Sharping sharping Joined 28 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.