fixed language switching in the frontend
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Support\LocaleConfig;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
@@ -11,23 +12,13 @@ class LocaleController extends Controller
|
||||
public function set(Request $request)
|
||||
{
|
||||
$locale = $request->input('locale');
|
||||
$supportedLocales = array_values(array_unique(array_filter([
|
||||
config('app.locale'),
|
||||
config('app.fallback_locale'),
|
||||
...array_filter(array_map(
|
||||
static fn ($value) => trim((string) $value),
|
||||
explode(',', (string) env('APP_SUPPORTED_LOCALES', ''))
|
||||
)),
|
||||
])));
|
||||
$supportedLocales = LocaleConfig::normalized();
|
||||
$canonical = LocaleConfig::canonicalize($locale);
|
||||
|
||||
if (empty($supportedLocales)) {
|
||||
$supportedLocales = ['de', 'en'];
|
||||
}
|
||||
|
||||
if (in_array($locale, $supportedLocales)) {
|
||||
App::setLocale($locale);
|
||||
Session::put('locale', $locale);
|
||||
Session::put('preferred_locale', $locale);
|
||||
if (in_array($canonical, $supportedLocales, true)) {
|
||||
App::setLocale($canonical);
|
||||
Session::put('locale', $canonical);
|
||||
Session::put('preferred_locale', $canonical);
|
||||
}
|
||||
|
||||
if ($request->expectsJson()) {
|
||||
|
||||
Reference in New Issue
Block a user