mcamara / laravel-localization

Easy localization for Laravel
MIT License
3.32k stars 507 forks source link

Dynamic and translated slug, unable to getLocalizedURL correctly #887

Closed StefanoTesla closed 7 months ago

StefanoTesla commented 7 months ago

Describe the bug I'm using spatie/laravel-translatable to save my models, in my models I have olso the translated slug.

My problem at the moment is how retrive the correct getLocalizedURL with the given locale, cause actually getLocalizedURL return the correct base address but the wring final slug.

Example:

en/route.php

<?php

return [
    "articles" => "articles"
    "single_article"    =>  "articles/{slug}",
];

fr/route.php

<?php

return [
    "articles" => "article"
    "seul_article"    =>  "article/{slug}",
];

single-article.blade.php

    <a rel="alternate" href="{{ LaravelLocalization::getLocalizedURL('en') }}">EN</a>
    <a rel="alternate" href="{{ LaravelLocalization::getLocalizedURL('fr') }}">FR</a>

If the url is: article/good-company

In the english page I get:

EN: https://mysite.com/articles/good-company FR: https://mysite.com/article/good-company In the french page I get:

EN: https://mysite.com/articles/bonne-compagnie FR: https://mysite.com/article/bonne-compagnie

How can solve this problem?