php - Laravel Multi-language Support -
i trying website support multiple languages, code not work:
route:
route::get('lang/{lang}', function($lang){ session::put('lang', $lang); return redirect::to('/'); });
main page:
<a href="{{ url::to('lang/fa') }}">[farsi]</a> <a href="{{ url::to('lang/en') }}">[english]</a>
language folders:
fa
folder have messages.php
:
return array( 'mainpage'=>'صفحه اصلی', );
en
folder have messages.php
:
return array( 'mainpage'=>'main page`, );
now trying use array have multi-language support , using code switch between languages:
{{ lang::get('messages.mainpage') }}
problem solved, @rezakho,
after adding line route.php
:
if ( session::has('lang') ) { app::setlocale(session::get('lang')); }
or change before
on filters.php
file:
app::before(function($request) { if ( session::has('lang') ) { app::setlocale(session::get('lang')); } });
Comments
Post a Comment