codezero-be / laravel-localized-routes

⭐️ A convenient way to set up and use localized routes in a Laravel app.
MIT License
504 stars 46 forks source link

Subdomain localized urls #73

Closed jeffsmor closed 1 year ago

jeffsmor commented 1 year ago

Hi...

I have the folowing supported locale array:

 'supported-locales' => [ 
        'en',
        'pt',
        'es',
    ],

And the following home blade view:

    {{ Route::localizedUrl('en') }}<br>
    {{ Route::localizedUrl('pt') }}<br>
    {{ Route::localizedUrl('es') }}

When I get mysite.test I see:

https://mysite.test
https://mysite.test/pt
https://mysite.test/es

Everything ok, when I change my supported locale array to:

    'supported-locales' => [
        'en' => 'mysite.test',
        'pt' => 'pt.mysite.test',
        'es' => 'es.mysite.test',
    ],

And get mysite.test again I see:

https://video-site.test
https://video-site.test
https://video-site.test

Is it a package issue?

Amazing package, by the way...

ivanvermeyen commented 1 year ago

Hello,

Did you call Route::localizedUrl('en') on a localized route?

If you call it on a localized route, then it should work.

However, if you call it on a route that is registered outside the Route::localized() closure, then it returns the same URL. This is because there are no localized versions of that route.

I did forget to include a test for that, so I'll add it.

jeffsmor commented 1 year ago

Hello,

Did you call Route::localizedUrl('en') on a localized route?

If you call it on a localized route, then it should work.

However, if you call it on a route that is registered outside the Route::localized() closure, then it returns the same URL. This is because there are no localized versions of that route.

I did forget to include a test for that, so I'll add it.

Yes.

This is my routes/web.php

Route::localized(function () {
    Route::get('/', function (Request $request) {
        return view('home');
    })->name('home');
});

And I'm calling the Route::localizedUrl('en') inside the view home.

ivanvermeyen commented 1 year ago

According to my test this should work. I also copied your setup to a fresh Laravel project and put it on GitHub. https://github.com/ivanvermeyen/domain-test

If you open the homepage at domain-test.test (the domains I configured) you should see 3 URL's:

Scherm­afbeelding 2023-02-19 om 13 15 06

I've added you to the project, so if you can replicate the issue I can try to fix it 👍

EDIT: Make sure your domains actually work. If they don't match the configured domains, you will get 3 times the same output.

jeffsmor commented 1 year ago

Hi man,,,

I got your project and it is really functional...

I came back to my one and I found out the issue.

I set:

'fallback_locale' => 'en',

When it is null I have what I am expecting.

However, I am just at the beginning of my project and soon I plan how the localized routes will work.

Thanks for now.

ivanvermeyen commented 1 year ago

That's definitely not working as intended :) I see it too now. Thanks for catching this, I will look into it.

ivanvermeyen commented 1 year ago

Should be fixed in 2.9.1 👍