-
-
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
getLocalizedURL does not translate slug #718
Comments
Did you follow all steps mentioned in the video tutorial https://www.youtube.com/watch?v=B1AUqCdizgc&feature=youtu.be ? |
Yes, I think so. In the video it shows only getting an object by any slug, and that works ok. The problem I have is related to URL translation.
When called from a view the parameter is a model instance, so 'getLocalizedRouteKey' is called on the model, returning the correct slug. I don't know enough of the inner workings of Laravelor or how the route parameters work, maybe it can only work after a response is sent ,but not on the request. I did not see anything related to this in the documentation, so I just expected it to work anywhere. Thank you for your time. |
If you are not using it yet, try Route Model Binding. I had the same issue and it was resolved when I changed my If you use the routes you mentioned, it could work if you change your controller method, for example: |
I have the same issue, did you fix it? |
When i try to get the localized URL of a model with translated route and slug, it returns the URL with the same slug (non localized), example:
LaravelLocalization::getLocalizedURL('en', 'aparato/caldera', [], true);
returns
http://site.test/en/device_type/caldera
instead of
http://site.test/en/device_type/boiler
I have the translated routes as follows:
in resources/lang/en/routes.php:
"device_type" => "device_type/{deviceType}",
in resources/lang/es/routes.php:
"device_type" => "aparato/{deviceType}",
and my routes are defined like this:
I use route model binding and implement
LocalizedUrlRoutable
, and have implementedresolveRouteBinding
andgetLocalizedRouteKey
in my model so that they return what i think they should, tested in tinker:so when i try to get the localized url, i get the following:
when I'd expect to get
"http://site.test/en/device_type/boiler"
I'm using laravel v. 7.6.1 and laravel-localization v. 1.5.0.
Using middleware
localize
,localeSessionRedirect
andlocalizationRedirect
in my routes.Config options:
Is this the expected behaviour? Any idea why it does not translate the slug?
Thank you.
The text was updated successfully, but these errors were encountered: