How to fetch current locale in view in Laravel 5.3

Fahad Khan picture Fahad Khan · Jan 6, 2017 · Viewed 27.8k times · Source

I am making a bilingual app. I am using same routes for each but I am using different views for both languages. Whenever I want to redirect to a route I want to pass {{ route('test.route', 'en') }}. Where I am passing en, I want to fetch the current locale value from the view and then pass it to the route. Please help.

Answer

Arun Code picture Arun Code · Jan 6, 2017

try this. It will give the locale set in your application

Config::get('app.locale')

Edit:

To use this in blade, use like the following, to echo your current locale in blade.

{{ Config::get('app.locale') }}

If you want to do a if condition in blade around it, it will become,

   @if ( Config::get('app.locale') == 'en')

   {{ 'Current Language is English' }}

   @elseif ( Config::get('app.locale') == 'ru' )

   {{ 'Current Language is Russian' }}

   @endif

To get current locale,

app()->getLocale()