php - Language locale does not change with App::setLocale but updates on Session::put() in laravel 5.2 -
am working on multi-lingual support laravel app, materials have seen online passing locale app facade , calling setlocale method translates website, have tried no luck.
in routes file, have this
route::group(['middleware' => ['web']], function () { route::get('change-locale', ['uses' => 'homecontroller@changelocale', 'as' => 'locale.change']); });
homecontroller@changelocale 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 been changed <b>'.$request->locale.'</b>')->withmessagetype('success'); } }
and in view sends request..
<ul class="dropdown-menu" aria-labelledby="dropdownmenu1"> @foreach(config('app.languages') $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 notification succesful, app::getlocale() still remains default , therefore website doesn't translated. need help.
are configuring locale session when application booting? in boot method of service provider, e.g:
// app/providers/appserviceprovider.php public function boot() { $locale = $this->app['session']->get('locale'); // same session()->get(... , session::get(... $this->app->setlocale($locale); // equal app()->setlocale(... , app::setlocale(... }
you might want here assure locale valid.
Comments
Post a Comment