What's the best logic for switching language in Laravel?

后端 未结 8 1673
遥遥无期
遥遥无期 2020-12-23 02:29

I\'m using Laravel localization to provide two different languages. I\'ve got all the path stuff set up, and mydomain.com/en/bla delivers English and stores the \'en\' sessi

8条回答
  •  被撕碎了的回忆
    2020-12-23 02:47

    You could have a Route to hand language change, for example:

    Route::get('translate/(:any)', 'translator@set');

    Then in the set action in the translator controller could alter the session, depending on the language code passed via the URL.

    You could also alter the configuration setting by using

    Config::set('application.language', $url_variable');

    Controller Example - translate.php

    public function action_set($url_variable)
    {
         /* Your code Here */
    }
    

提交回复
热议问题