问题描述:

I'm not getting any errors when switching languages on my production server.

I can see the session value being changed as the flag on my navbar changes but setting the locale isn't working.

Everything works fine on localhost though.

Im not quite sure where to approach this problem from so I'd really appreciate it if someone can point me in the right direction.

网友答案:

It looks like you need to clear config cache at production:

php artisan config:cache

This came to my mind when I read your comment:

Yes. Apparently, I played around with the config and the locale is always falling to the fallback_locale section of the config file app.php. I tried setting fallback_locale to my second language and the site did infact change language. But I was then unable to switch back to the first language.

网友答案:

The example I talked in the comment is this

use Closure, Session, Auth, App;

class LocaleMiddleware {


    public function handle($request, Closure $next){

        if(Auth::user() ){
          App::setlocale(Auth::user()->lang);
        }elseif($locale = Session::has('lang')){
          $local = Session::get('lang');
          App::setlocale($local);
        }
        return $next($request);
    }
}
网友答案:

My site supported two locales, "en" and "th"

The issue was that I was setting the session('lang') key to "EN" and "TH".

On my mac environment, things like these are not case sensitive and therefore locales worked properly on my machine environment.

However, on a live production server which likely is running on Linux etc, it is case sensitive.

I fixed the issue by now setting the session key "lang" to lower case values of the Locales.

相关阅读:
Top