laravel-localization
laravel-localization copied to clipboard
Bad redirection for translated routes with parameters, possible problem in findTranslatedRouteByPath()
Hi, i found some problems with redirection for routes with parameters. When language in my browser/cookie is set to en and then i go directly to translated url with parameters i get 404 error.
Example: .env APP_LOCALE=fr APP_SUPPORTED_LOCALES=en,fr
Config: useAcceptLanguageHeader = true hideDefaultLocaleInURL = true
Routes: EN: "play_single" => "play/{lottery}", FR: "play" => "jwe/{lottery}",
Steps to reproduce: 1.) Set your language to en, 2.) Go to page /play/my-lottery 3.)Go to page /jwe/my-lottery - it will redirect you to /en/jwe/my-lottery instead of just /jwe/my-lottery - you get 404 error
So if you use page in 'en' and your friend sends you link in different language you will occur 404. Problem is not visible when i use hideDefaultLocaleInURL = false.
I found that function findTranslatedRouteByPath() may not properly comparing routes which has attributes. Comparsion looks like: LEFT: $this->translator->get($translatedRoute, [], $url_locale) = "play/{lottery}" RIGHT: rawurldecode($path) == "play/my-lottery" Result: "play/{lottery}" != "play/my-lottery"
Translation cannot be found for routes with params
More info: Laravel 8 PHP8 LaravelLocalization: 1.6.1
I fixed this behavior with checking params in $path and replacing route attributes for comparrsion.
Is there a bug, or this feature is not implemented yet? Or maybe my configuration is wrong.
I second this issue, i have the same problem, same configuration !
Same issue, any translated routes with attributes fail when doing a call to getLocalizedURL().