Comments (9)
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!
from laravel-tongue.
@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
from laravel-tongue.
I've tried with another language es
on another subdomain es.my_domain.dv. The funny thing is :
- Visiting es.my_domain.dv :
app()->getLocale() === 'es'
(correct) - Visiting my_domain.dv :
app()->getLocale() === 'es'
(wrong😢 ) - Visiting en.my_domain.dv :
app()->getLocale() === 'en'
(correct) - Visiting my_domain.dv :
app()->getLocale() === 'en'
(!!!)
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.
from laravel-tongue.
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
from laravel-tongue.
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.
from laravel-tongue.
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 ^^
from laravel-tongue.
@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
from laravel-tongue.
@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 !
from laravel-tongue.
@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
from laravel-tongue.
Related Issues (13)
- Best way to omit subdomain when locale == fallback_locale? HOT 2
- Use custom subdomain instead of locale string? HOT 2
- route:cache HOT 1
- no running in local environment HOT 16
- Other subdomains won't behave correctly HOT 1
- Supported locales must be properly defined. HOT 2
- dialect()->translate() doesn't work on controllers HOT 1
- Laravel 9 compatitble HOT 2
- Reverse alias operation
- always getting en as a default locale, even config/app is ar HOT 2
- foreach -> mcamara ?? HOT 1
- Need Help: Travis is failing just with a little change (worked before perfectly) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-tongue.