Answer the question
In order to leave comments, you need to log in
Language change not working in laravel 5.3?
It is expected that when clicking on a link in a view, the language will switch from Russian to English (if Russian is installed) and vice versa (if English is installed).
But that doesn't happen. The language does not change.
View:
<html>
<body>
<a href="{{route('change_locale', trans('country.others.locale'))}}">@lang('country.others.change_locale')</a>
</body>
</html>
Route::get('locale/{locale}', '[email protected]')->name('change_locale');
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
class SystemsController extends Controller
{
public function changeLocale($locale)
{
if (in_array($locale, ['ru', 'en'])) {
session()->put('locale', $locale);
App::setLocale(session('locale'));
}
return redirect()->back();
}
}
<?php
return [
'form' => [
'description' => "Enter new countries name",
'send' => 'Send'
],
'others' => [
'change_locale' => 'Change language',
'locale' => 'ru'
]
];
<?php
return [
'form' => [
'description' => 'Введите название новой страны',
'send' => 'Отправить',
],
'others' => [
'change_locale' => 'Сменить язык',
'locale' => 'en'
]
];
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question