How can I find the current language in a Laravel view

0 votes
I'm using the Laravel Lang class for localization of my web app. I've added two languages to the languages array in application/config/application.php. This changes the default language it uses for localization to whatever the first part of the URI indicates (e.g. bla.com/en/bla and bla.com/co/bla). Now I need to be able to check what the current default language is in my view.

However, the Lang class provides no way of checking this as far as I've been able to figure out, as the Lang::$language variable is protected. Is there any way of checking this apart from manually parsing the URI?
Dec 3, 2020 in Laravel by kartik
• 37,520 points
229 views

1 answer to this question.

0 votes

Hello @kartik,

The cleanest way to know the current language of your website in Laravel appears to be :

Lang::locale();

It's different than this command that will return the default language of your website :

Config::get('app.locale');
answered Dec 3, 2020 by Niroj
• 82,760 points

Related Questions In Laravel

0 votes
1 answer

How Can I Remove “public/index.php” in the URL Generated Laravel?

Hello @kartik, If it isn't already there, create ...READ MORE

answered Aug 10, 2020 in Laravel by Niroj
• 82,760 points
5,607 views
0 votes
1 answer

How can I create a unique random string in laravel?

Hello @kartik, You can use : sha1(time()) Explanation: sha1 is ...READ MORE

answered Sep 25, 2020 in Laravel by Niroj
• 82,760 points
1,035 views
0 votes
1 answer

How can I modify a migration in Laravel?

Hello @kartik, You should create a new migration ...READ MORE

answered Sep 27, 2020 in Laravel by Niroj
• 82,760 points
849 views
0 votes
1 answer

How can I build a condition based query in Laravel?

Hello @kartik, Try this: $query = DB::table('node'); if ($published == ...READ MORE

answered Sep 27, 2020 in Laravel by Niroj
• 82,760 points
109 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,760 points
7,734 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,760 points
867 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,760 points
699 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,760 points
8,194 views
0 votes
1 answer

How can I echo the version of the current Laravel version in php using the view?

Hello @kartik, This is the way how to ...READ MORE

answered Aug 10, 2020 in Laravel by Niroj
• 82,760 points
311 views
0 votes
1 answer

How Can I Set the Default Value of a Timestamp Column to the Current Timestamp with Laravel Migrations?

Hello, To create both of the created_at and updated_at columns: $t->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP')); $t->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP on update ...READ MORE

answered Apr 2, 2020 in Laravel by Niroj
• 82,760 points
6,711 views