Am working on multi-lingual support for my laravel app, all the materials have seen online say that passing the locale to the App facade and calling the setLocale method translates the website, I have tried it but no luck.
In my routes file, I have this
Route::group(['middleware' => ['web']], function () {
Route::get('change-locale', ['uses' => 'HomeController@changeLocale', 'as' => 'locale.change']);
});
HomeController@changeLocale I have...
namespace Gudaapp\Http\Controllers;
use Illuminate\Http\Request;
use Gudaapp\Http\Requests;
use Gudaapp\Http\Controllers\Controller;
class HomeController extends Controller
{
public function changeLocale(Request $request) {
if(empty($request->locale)) { redirect()->back()->withMessage('Unknown locale, please, if problem persists, contact admin.'); }
session()->put('locale', $request->locale);
return redirect()->back()->withMessage('Your locale has now been changed to <b>'.$request->locale.'</b>')->withMessageType('success');
}
}
and in the view that sends the request..
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
@foreach(config('app.languages') as $locale => $lang)
<li class="{{ session('locale') == $locale ? 'active' : '' }}">
<a href="{!! route('locale.change', ['locale'=> $locale]) !!}" ><img src='{!! asset($lang["flag"]) !!}' alt="" /> {{ $lang['language'] }}</a>
</li>
@endforeach
</ul>
I always get the notification that it was succesful, but App::getLocale() still remains the default and therefore the website doesn't get translated. I need help.