Skip to content
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

Bad redirection for translated routes with parameters, possible problem in findTranslatedRouteByPath() #821

Open
pawelsome opened this issue Mar 3, 2022 · 2 comments
Assignees
Labels

Comments

@pawelsome
Copy link

pawelsome commented Mar 3, 2022

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

Is there a bug, or this feature is not implemented yet? Or maybe my configuration is wrong.

@blackjak231
Copy link

I second this issue, i have the same problem, same configuration !

@seche
Copy link

seche commented Jun 8, 2023

Same issue, any translated routes with attributes fail when doing a call to getLocalizedURL().

@iwasherefirst2 iwasherefirst2 self-assigned this Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants