-
-
Notifications
You must be signed in to change notification settings - Fork 512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not working with cached routes #201
Comments
Not sure if it will work with sessions and route translations, but try this: In your routes.php, set the localized group prefix to '{locale?}', instead of Localization::setLocale(), and add set_locale middleware before other localization middlewares: Route::group(
[
'middleware' => ['set_locale', 'localizationRedirect', 'localeSessionRedirect'],
'prefix' => '{locale?}'
],
function()
{
Route::get('/', 'HomeController@getIndex');
}
); The set_locale middleware, added to your kernel, will grab the locale? parameter and set it as the current locale: class SetLocale implements Middleware {
public function handle($request, Closure $next)
{
$locale = $request->route('locale');
Localization::setLocale($locale);
return $next($request);
}
} |
Thanks! It works for setting up the routes correctly, but now using |
Yeah, I can see how this solution could break a few things. A workaround is to send the current locale as a parameter to the url generator. URL::route( 'profile', [ 'locale' => LaravelLocalization::getCurrentLocale() ] ) I made this helper function to get a localized URL: function route_local($name, $parameters = array(), $absolute = true, $route = null)
{
$parameters = array_merge($parameters, ['locale' => (string) LaravelLocalization::getCurrentLocale()]);
return app('url')->route($name, $parameters, $absolute, $route);
}
|
I'm having the same problem but change the route generates an error. "Class set_locale does not exist". |
Any way to make it work with cached routes? (using
php artisan route:cache
)The text was updated successfully, but these errors were encountered: