Search code examples
phplaravellaravel-localization

How to get the current language in Laravel while the url is not changing,


I am using two languages for my Laravel project. The default language is English. Another language is 'Bangla`. For that, I have created

  • a folder inside resources/lang/bn.
  • Localization middleware inside Http/Middleware.
  • add Localization class inside the kernel.php under middlewareGroups array.
  • add list item english and bangla in the menubar for choosing language <li><a href="{{ 'locale/en' }}">English</a></li> <li><a href="{{ 'locale/bn' }}">Bangla</a></li>

So while I clicked any language my site URL is not changing but the menubar language is changed.

Now my question is how can I find the selected current language in my blade template while my site URL remains same for selecting any language ?


Solution

  • you can use {{ app()->getLocale() }}