-
-
Notifications
You must be signed in to change notification settings - Fork 512
Description
Hello !
Thank you first for this wonderful package!
Describe the bug
When using the function LaravelLocalization::getLocalizedURL to translate a route containing a parameter, the route gets well translated with a normal string like "my-slug", but it is not translated when the slug contains a "/" like "my-slug/my-second-slug"
To Reproduce
Create a route with a parameter that accepts the "/" character :
Route::get(LaravelLocalization::transRoute('routes.news.category'), 'category')->name('category')->where(['slug' => '[a-z0-9\-\/]*']);
Put its translations inside the fr.json and en.json :
FR :
{
"routes.news.category":"actualites\/{slug}"
}
EN :
{
"routes.news.category":"news\/{slug}"
}
Go to tinker and try with a simple slug first :
$slug = "slug-news-category";
$route = route('front.news.category', $slug);
// "https://{domain.ext}/fr/actualites/slug-news-category"
\LaravelLocalization::getLocalizedURL('en', $route, []);
// Translation OK : https://{domain.ext}/en/news/slug-news-category
With a / in the slug, it breaks :
$slug = "slug-news-category/second-category";
$route = route('front.news.category', $slug);
// "https://{domain.ext}/fr/actualites/slug-news-category/second-category"
\LaravelLocalization::getLocalizedURL('en', $route, []);
// Translation KO : https://{domain.ext}/en/actualites/slug-news-category/second-category
Expected behavior
Translation should be : https://{domain.ext}/en/news/slug-news-category/second-category
More info:
- Version of Laravel : 11.37
- Version of the Laravel-localization package : 2.2.1
- Which middleware is used in
Route::groups
: "web" + LocaleSessionRedirect + LaravelLocalizationRedirectFilter + LaravelLocalizationViewPath + LaravelLocalizationRoutes
Config file :
return [
'supportedLocales' => [
'en' => ['name' => 'English', 'script' => 'Latn', 'native' => 'English', 'regional' => 'en_GB'],
'fr' => ['name' => 'French', 'script' => 'Latn', 'native' => 'français', 'regional' => 'fr_FR'],
],
'useAcceptLanguageHeader' => true,
'hideDefaultLocaleInURL' => false,
'localesOrder' => ['fr','en'],
'localesMapping' => [],
'utf8suffix' => env('LARAVELLOCALIZATION_UTF8SUFFIX', '.UTF-8'),
'urlsIgnored' => ['/skipped'],
'httpMethodsIgnored' => ['POST', 'PUT', 'PATCH', 'DELETE'],
];
Additional context
You will surely have understood that but I'm french so my default locale everywhere is "fr".