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

Default subdomain FR #31

Closed
rseon opened this issue Mar 12, 2020 · 9 comments
Closed

Default subdomain FR #31

rseon opened this issue Mar 12, 2020 · 9 comments

Comments

@rseon
Copy link

rseon commented Mar 12, 2020

First : thanks a lot for this package, good job !

I would like to set default language as fr (without subdomain) and a subdomain for en.

In /app/config.php :

'locale' => 'fr',
'fallback_locale' => 'en'

When I visit the domains :

However, when I use dialect()->current('fr') it returns fr.my_domain.dv and dialect()->current('en') returns my_domain.dv

How can I fix it ?
Thanks a lot !

@pmochine
Copy link
Owner

pmochine commented Mar 13, 2020

First, thank you for your nice words! And now to your issue. I just tested a simple Laravel demo and even app()->getLocale() shows the wrong language. That's super weird! I will find it out!

@pmochine
Copy link
Owner

pmochine commented Mar 13, 2020

@rseon OK I think I know what's up.

So this can lead to a discussion on what is right and what is wrong...

The solution of your problem is to set your 'fallback_locale' => 'fr'

Here is why: https://github.com/pmochine/Laravel-Tongue/blob/master/src/Tongue.php#L89

If we don't find any locale in your URL, we assume we need to go to your fallback main language. That is in your case fr. We assume that your fallback language will always have a translation.

'locale' => 'fr', is with this package useless because we try to detect the language first via the browser or the cookies. And the value is always variable. That means app()->getLocale() shows us always a different locale

Tell me what you think

@rseon
Copy link
Author

rseon commented Mar 14, 2020

I've tried with another language es on another subdomain es.my_domain.dv. The funny thing is :

So without subdomain, the last locale is used (cookie I think ?)
I've tried with 'fallback_locale' => 'fr', no change.

My routes are not translated and {{ dialect()->current('fr') }} returns http://fr.my_domain.dv.

I continue to investigate.

@pmochine
Copy link
Owner

Do you have the middleware active? So that the redirection is working properly?

Because in your example when you go back to your domain without the subdomain it always has the latest locale you have used

@rseon
Copy link
Author

rseon commented Mar 14, 2020

When I set the middleware globally in the RouteServiceProvider@mapWebRoutes, I'm redirected to en.my_domain.dv.
If I set it on the route file (using Route::group([ 'middleware' => [ 'speaks-tongue' ]], function() { ... });, only the localized routes are redirected to the en subdomain.

@rseon
Copy link
Author

rseon commented Mar 14, 2020

Another funny thing is if I vist fr.my_domain.dv, I'm redirected to my_domain.dv and locale is correct...

But from another language, {{ dialect()->current('fr') }} returns http://fr.my_domain.dv without localized route.

I'm lost ^^

@pmochine
Copy link
Owner

pmochine commented Mar 16, 2020

@rseon Okay, could you do me a favour. Create a fresh Laravel project and install my package. And try to create a minimal Laravel package, so I can see your problems.
And if possible, write down the issues you have again in a readme file, so I can work on those.

Thank you :)

p.S. sorry that I couldn't reply so soon, our city is completely locked down... funny times

@rseon
Copy link
Author

rseon commented Mar 17, 2020

@pmochine You can find the test repo there : https://github.com/rseon/laravel-tongue-test

Thanks for your review, and good luck for these funny times !

@pmochine
Copy link
Owner

@rseon So thank you for your test repo. You find a pull request where I have change some things.

And thank you, because of you I found some small bugs. dialect()->redirectUrl(route('home'), 'fr') This part was indeed a bug. I am actually not sure why I wrote this like that. There are not options like this. You should have used translate.

New patch coming soon

@pmochine pmochine closed this as completed May 3, 2020
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

2 participants