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

Nested slugs not translatable in language switcher #870

Open
Elkex opened this issue May 23, 2023 · 5 comments
Open

Nested slugs not translatable in language switcher #870

Elkex opened this issue May 23, 2023 · 5 comments

Comments

@Elkex
Copy link

Elkex commented May 23, 2023

Hello,

This package seems to work perfectly to translate slugs on the first level of the URL, but seems to fail for the second level of a nested URL.

For instance:
/en/teachers translates perfectly in the language switcher to /fr/professeurs

However, if I have a second level page:
/en/teachers/apply does not translate to /fr/professeurs/appliquer, it shows /fr/teachers/apply

I implemented the package accordingly with the Twill CMS, but once the slug is nested, it does not seem to translate correctly.

@vgaldikas
Copy link

vgaldikas commented Jun 24, 2023

I have same issue. I did some digging into the source code, and it appears that the issue arises because for some reason, when you add the second dynamic segment the getRouteNameFromAPath stops resolving the $routeName in Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes

@vgaldikas
Copy link

vgaldikas commented Jun 24, 2023

Hey @Elkex I got it working as expected.

initially I was defining route as such:

'categories.index' => 'c/{category}/{manufacturer:slug?}'

After some trial and error i ended up doing the following:

define route as such:

'categories.index' => 'c/{category}/{manufacturer?}'

Then add these 2 methods to my Manufacturer model:

    public function getRouteKeyName(): string
    {
        return 'slug';
    }

    public function getLocalizedRouteKey($locale)
    {
        return $this->slug;
    }

And you got to implement the `Mcamara\LaravelLocalization\Interfaces\LocalizedUrlRoutable' on your model too.

So far didn't found any problems

@vgaldikas
Copy link

Actually @mcamara maybe could you weigh in, is this i a potential bug, or is this expected behavior? I could take a look at either creating pull request for documentation detailing how to make this work, or if it's a bug, I would maybe debug further to get it to work both ways?

@mcamara
Copy link
Owner

mcamara commented Jun 26, 2023

Thanks for asking @vgaldikas , feel free to create a PR and @iwasherefirst2 or I will review it.

@StefanoTesla
Copy link

Actually @mcamara maybe could you weigh in, is this i a potential bug, or is this expected behavior? I could take a look at either creating pull request for documentation detailing how to make this work, or if it's a bug, I would maybe debug further to get it to work both ways?

Did you understand the problem? I don't really understand how to solve the same problem..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants