fixed language switching in the frontend

This commit is contained in:
Codex Agent
2025-12-02 13:31:58 +01:00
parent 28539754a7
commit dd3198cb79
20 changed files with 395 additions and 203 deletions

View File

@@ -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()) {