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

后端 未结 8 1628
遥遥无期
遥遥无期 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:52

    This question still comes in Google search, so here's the answer if you're using Laravel 4 or 5, and mcamara/laravellocalization.

    • {{ trans('common.chooselanguage') }}:
    • @foreach(LaravelLocalization::getSupportedLocales() as $localeCode => $properties)
    • {{{ $properties['native'] }}}
    • @endforeach

    NOTE that this example shows flags (in public/img/flags/{{locale}}.gif), and to use it you will need a bit of .css, but you can modify it to display the text if you want...

    FYI. The mcamara/laravellocalization documentation has examples and a LOT of helpers, so look through the documentation on github. (https://github.com/mcamara/laravel-localization)

提交回复
热议问题