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

hideDefaultLocaleInURL = TRUE laravel 5 session issue #219

Closed
onlymega opened this issue May 20, 2015 · 11 comments
Closed

hideDefaultLocaleInURL = TRUE laravel 5 session issue #219

onlymega opened this issue May 20, 2015 · 11 comments

Comments

@onlymega
Copy link

I have two enabled languages: "en" (default) and "ru"
When I am adding /ru to url - app automatically writes "ru" as selected language in session:
http://example.com/ru/auth/login (sets session locale to "ru")
But when using default url with hideDefaultLocaleInURL set to TRUE it doesn't update the session locale:
http://example.com/auth/login (redirects to http://example.com/ru/auth/login instead of updating session locale to default "en").

The temporary solution is to call http://example.com/en/auth/login that will redirect to http://example.com/auth/login and will set session locale to en.

This issue also prevents the translation selection combobox to work right:
getLocalizedURL returns example.com/auth/login instead of example.com/en/auth/login (if session locale is set to "ru" it will not update it to "en")

Please fix this issue or just write a "tip" about this.
Thanks!

@Riesjart2
Copy link

+1

2 similar comments
@texnika01
Copy link

+1

@c2pdev
Copy link

c2pdev commented Jun 28, 2015

+1

@sandrodz
Copy link

sandrodz commented Aug 2, 2015

+1 this is annoying bug :)

@Riesjart2
Copy link

Any plans to fix this (major) bug? Thanks!

@thoth3x
Copy link

thoth3x commented Jan 3, 2016

+1

@mxmtsk
Copy link
Contributor

mxmtsk commented Jan 7, 2016

+1

@mxmtsk
Copy link
Contributor

mxmtsk commented Jan 7, 2016

I think I fixed it by changing LocaleSessionRedirect.php to this:

https://gist.github.com/mxmtsk/308badf0b9553aabe86e

It works for me, if you guys could try it also. I basically put line 26 before line 19 because $locale was undefined in the first if statement.

@arcanedev-maroc
Copy link

@mxmtsk, try to make a PR to see if it's gonna pass all the tests or not.

@mcamara mcamara closed this as completed in 68a64cb Jan 8, 2016
mcamara pushed a commit that referenced this issue Jan 8, 2016
Fix #219 - $locale was undefined
@mcamara
Copy link
Owner

mcamara commented Jan 8, 2016

I have merged your PR and adapted it to version 1.1 and 1.0. Thanks for your help!

@DanDvoracek
Copy link

DanDvoracek commented Oct 27, 2017

It looks like an exception went through that fix, at least for me. When setting hideDefaultLocaleInUrl to true I had trouble switching language through the url.

Let's say I was on the page /en/events and replaced that bit of the url by /evenements (fr), it would redirect me to /en/events. My default locale is indeed set in french as you can see

Therefore I stumbled on this post that gave me the direction for where to look at.

I found that adding this snippet on line 33 of the LocalSessionRedirect.php class does the trick for me:

if (count($params) === 1 &&  !(app('laravellocalization')->checkLocaleInSupportedLocales($params[0])) ) {
          session([ 'locale' => App::getLocale() ]);
          return $next($request);
        }

So far I could not find any issue with it. If that makes sense for it to be implemented by default, I'm more than happy to do a PR. By the way, if there would be anything wrong with this snippet, feel free to let me know. I just tried the package for the first time today.

❤️

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

10 participants