I'm wanting to build links to different locale versions of the current route, based on whatever the current route is. This is for linking to different language versions for the current page in a generic manner. This is for use in a language dropdown selector.
This code works:
localized_route(substr(Route::currentRouteName(), 3), [], 'fr')
but is not such an elegant solution.
Route::currentRouteName() returns the localized version of the current route name, such as en.home.index. Maybe we need something which will return the current route name without the locale prefix? Route::parentRouteName() or similar? Or a parent_route_name() helper function. I struggled with how to name it, so perhaps there is a better way.
Or maybe even a simpler overall method, which will convert the current route to a different locale route. Something like: current_route('fr') which would return the French locale version of the current route.
Hi, it's me again 😅.
I'm wanting to build links to different locale versions of the current route, based on whatever the current route is. This is for linking to different language versions for the current page in a generic manner. This is for use in a language dropdown selector.
This code works:
localized_route(substr(Route::currentRouteName(), 3), [], 'fr')
but is not such an elegant solution.Route::currentRouteName()
returns the localized version of the current route name, such asen.home.index
. Maybe we need something which will return the current route name without the locale prefix?Route::parentRouteName()
or similar? Or aparent_route_name()
helper function. I struggled with how to name it, so perhaps there is a better way.Or maybe even a simpler overall method, which will convert the current route to a different locale route. Something like:
current_route('fr')
which would return the French locale version of the current route.Thanks for the help!