Mert Akdeniz
Mert Akdeniz

Reputation: 33

Laravel 5 - Localization not working

I tried to localization my application, but seems like I'm missing something. Here is my routes.php

Route::get('dil/{dil}', 'CoreController@languageChoose');

And here is my CoreController.php

    <?php namespace Secret\Http\Controllers;

    use Auth;
    use Session;
    use Input;
    use Redirect;

class CoreController extends Controller {

    public function languageChoose($dil)
    {
        Session::set('locale', $dil);
        return Redirect::back();
    }
}

I'm using

{{ Config::get('app.locale') }}

on my blade so I can show which language is current. But it always says "tr" which is the default language has choosen by me on config/app.php. What am I missing? I'm trying to change language by "app.foo/dil/en"

Upvotes: 1

Views: 2150

Answers (1)

Bernig
Bernig

Reputation: 462

First, setting a session item named "locale" doesn't interact in any way with your "app.locale" configuration. So {{ Config::get('app.locale') }} will always return your default language.

Creating a session item :

Session::put('key', 'value');

or

session(['key' => 'value']);

Retrieving a session item :

$value = Session::get('key');

or

$value = session('key');

As described in the documentation : http://laravel.com/docs/5.0/session

Note that if you were willing to edit your config value for "locale" by doing Config::set('app.locale', $dil), the change would not be permanent and you would have to set it again in every new request.

Upvotes: 2

Related Questions