You need to set the app's locale to the choosen language, e.g.: \App::setLocale($language);
In our applications all urls are prefixed with the language, for instance: /en/user/list And a custom middleware just sets the locale on every request using the first URL segment.
Thanks for the reply. Please break it down for me because I'm not a Laravel or PHP expert.
I want to have two idioms: EN and PT.
Have set the middleware in App/Html/MiddlewareApp.php:
<?php namespace App\Http\Middleware;
use Closure;
class App {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if(!\Session::has('locale'))
{
\Session::put('locale', \Config::get('app.locale'));
}
app()->setLocale(\Session::get('locale'));
return $next($request);
}
}
In kernel.php:
'App\Http\Middleware\App',
LanguageController.php:
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller; use Auth; use Session; use Input; use Redirect; use Illuminate\Http\Request;
class LanguageController extends Controller {
public function index()
{
Session::set('locale', Input::get('locale'));
return Redirect::back();
}
}
Routes.php:
Route::post('/language', array(
'before' => 'csrf',
'as' => 'language-choose',
'uses' => 'LanguageController@choose'
));
In Config/App.php I have:
'locale' => 'en',
Do I need to add 'pt' ?
Thank you.
You are triying to reinvent the wheel dude. Check out this package: https://github.com/mcamara/laravel-localization
jartaud said:
You are triying to reinvent the wheel dude. Check out this package: https://github.com/mcamara/laravel-localization
Yes, have worked on that package since yesterday. It's not fully working but I'm getting there.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community