A
A
Alexander Ampleev2019-03-10 07:17:35
Laravel
Alexander Ampleev, 2019-03-10 07:17:35

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).
5c848fdac4dd2221438836.png
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:
Route::get('locale/{locale}', '[email protected]')->name('change_locale');

Controller:
<?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();
    }
}

en/country.php
<?php

return [
    'form' => [
        'description' => "Enter new countries name",
        'send' => 'Send'
    ],
    'others' => [
        'change_locale' => 'Change language',
        'locale' => 'ru'
    ]

];

en/country.php
<?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 question

Ask a Question

731 491 924 answers to any question