chinleung / laravel-multilingual-routes

A package to handle multilingual routes in your Laravel application.
https://github.com/chinleung/laravel-multilingual-routes-demo
MIT License
395 stars 25 forks source link

Add a way to get the current route name without the localization #25

Closed Firer closed 4 years ago

Firer commented 4 years ago

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 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.

Thanks for the help!

chinleung commented 4 years ago

@Firer I've added the helper current_route('fr'); which would return the French version of the current route as you've suggested!

It will be available as of v1.5.0.