Based on this thread , I have tried to implement an additional English language for the site, the default French and does not use the prefix, so something like , and switch to English would be , I would like to have the URL-address for the contact pages such as and for English and French versions respectively. www.website.comwww.website.com/en/www.website.com/en/contactwww.website.com/contact
My current .php routes
if (Request::segment(1) == 'en') {
App::setLocale(Request::segment(1));
Config::set('app.locale_prefix', Request::segment(1));
}
else {
App::setLocale('fr');
Config::set('app.locale_prefix', '');
}
Route::group(array('prefix' => Config::get('app.locale_prefix')), function()
{
Route::get(
'/',
function () {
return view('index');
}
);
Route::get(
'/contact/',
function () {
return view('contact');
});
});
My header file in which the flag icon to switch the language
@if (Lang::locale() == 'fr')
<a href="{{ url('/en/' . Request::segment(1)) }}"><img src="{{asset('images/GB.png')}}"></a>
@elseif (strcasecmp(Request::segment(1), 'en') == 0 && Request::segment(2) != NULL)
<a href="{{ url( Request::segment(2)) }}"><img src="{{asset('images/FR.png')}}"></a>
@else
<a href="{{ url( '/') }}"><img src="{{asset('images/FR.png')}}"></a>
@endif
and method for generating urls
<a class="block-title" href="{{ (strcasecmp(Request::route()->getPrefix(), '/en') == 0) ? url('en/contact') : url('/contact') }}">CONTACT</a>
I would like to know a cleaner way to generate them and how can I get for the English URL of the main page www.website.com/en/insteadwww.website.com/en
Thank you so much!