Closed illuminate3 closed 9 years ago
I can't help much if you don't provide the outcome of your code, haha. What are the errors?
lol ..
It just defaults to the default locale if the "en" directory is included. "kotoba::general.home" is just "home" in English. The Spanish should be "portada" (<-- I doubt this a correct translation)
IF I remove the "en" default locale it will just show "kotoba::general.home".
The same will occur if I use "Lang::choice('')"
Just tested on a clean install, and all trans()
, Lang::choice()
and Lang::get()
methods work for me without issue.
ok, will look into what I'm doing that is causing this issue. Thanks!
Ok, this works when you set locale=>'es' directly but I'm trying to set it with a middleware using
App::setLocale(Session::get('locale'));
I'm gonna take a look again by reducing the number of modules I'm running.
I would check the loading order. I think packages are loaded and registered before middleware are. I could be wrong though.
Here's what I got:
protected $middleware = [
'App\Http\Middleware\SetTheme',
'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
'Illuminate\Cookie\Middleware\EncryptCookies',
'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
'Illuminate\Session\Middleware\StartSession',
'Illuminate\View\Middleware\ShareErrorsFromSession',
'App\Http\Middleware\VerifyCsrfToken',
'App\Http\Middleware\SetLanguage',
];
class SetLanguage implements Middleware {
public function __construct(Request $request)
{
$this->request = $request;
// fix for setting App::locale
$lang = Session::get('locale');
if ($lang == null) {
Session::set('locale', Config::get('app.locale'));
}
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
//dd(Config::get('app.locale'));
//dd(Session::get('locale'));
//dd(Session::has('locale'));
$lang = Session::get('locale');
if ( $lang != App::getLocale() ) {
if ( Session::has('locale') && array_key_exists(Session::get('locale'), Config::get('languages.supportedLocales')) ) {
App::setLocale(Session::get('locale'));
//dd('here');
} else {
App::setLocale(Config::get('app.fallback_locale'));
}
}
return $next($request);
}
}
hmmmm....
Again, service providers are loaded before middleware are.
Service providers are the key to bootstrapping a Laravel application. The application instance is created, the service providers are registered, and the request is handed to the bootstrapped application [excerpt taken from the Laravel documentation].
Read more on the lifecycle here: http://laravel.com/docs/5.0/lifecycle#lifecycle-overview
Create a new service provider to set the language, and simply make sure that it is registered before your menu service provider.
I also tried with Laravel's default files.
NOTE: I've been tweeking my L5 install so that it is possible that I have a conflict with my own middleware or something else on my side.