-
-
Notifications
You must be signed in to change notification settings - Fork 513
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
Translatable route parameters isn't work when wich language ? #885
Comments
Did you get a fix for this, i am currently experiencing the same issue. |
I had the same problem in the past, you didn't paste your controller middlware setting to go deeper in this problem |
Hi! Same issue here, only the locale change in the url, nothing else. Example code: Route::group([
'prefix' => LaravelLocalization::setLocale(),
'middleware' => ['localize', 'localizationRedirect', 'localeSessionRedirect'],
], function () {
Route::get(LaravelLocalization::transRoute(__('/{user}/wish/{wish}')), WishIndexController::class);
}); fr.json {
"/{user}/wish/{wish}": "/{user}/souhait/{wish}",
} Selector EN: en/username/wish/my-x-mas-idea Should be: Selector FR: fr/username/souhait/my-x-mas-idea ✅ Hopefully a fix or a workaround? 🤞🏻 |
I found the way to make it work finally! I will write how on monday |
So here I am. Routes EN:
Routes IT:
Web.php:
Model Products:
ProductController:
view:
Advisor: My problem was find the way to overwrite the way as Laravel resolve the model url, and get the right "alternate" link. First thing we need to care is the model shoud implement \Mcamara\LaravelLocalization\Interfaces\LocalizedUrlRoutable ❌❌❌❌❌❌ Worng way ❌❌❌❌❌❌
❌❌❌❌❌❌ Worng way ❌❌❌❌❌❌ ✅✅✅✅✅ Correct Way ✅✅✅✅✅✅✅
In the model we need olso two more methods, one is getLocalizedRouteKey
This metods is called when we call LaravelLocalization::getLocalizedURL('en') or any others locale, in my example is the way how I can get the translated version of the slug using spatie/laravel-translatable feel free to write your correct way. And the laravel provided method resolveRouteBinding() Always in the method we need to add this:
This method will be called from the controller to get the right model,
But we need to do some consideration before, The controller method should have the the Model as input parameter, the variable should be named as the model column we want to find. You can put a dd() inside the resolveRouteBinding to ensure that is fired. |
The problem noy is how to get two nested dynamics url :( |
I see class ProductsController extends Controller {
public function show(Product $slug)
{
return view('product', compact('slug'));
}
} if we can't use it like this then the well, In case it is resolved. But, I am looking for like this : public function show($slug)
{
return Product::findBySlug($slug);
} Anyone can give me a solution how can I solve this? |
@mcamara Pls feedback |
Describe the bug
Translatable route parameters
http://url/en/article/important-change
http://url/es/articulo/cambio-importante
I setup like example, when access directly from url it ok. But when use button change language (also like example Creating a language selector). it show url 404. if not have parameters, it ok.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
when change language ES, it redirect to http://url/es/articulo/cambio-importante
More info:
Route::groups
: 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath'supportedLocales
: all,useAcceptLanguageHeader
: false andhideDefaultLocaleInURL
:true).it seems code in button change language have issue, it not generate to url belong to this language
The text was updated successfully, but these errors were encountered: