Files
Toiminnanohjaus/app/Modules/Users/Presentation/Http/Middleware/SetLocale.php
T
petriandClaude Opus 5.5 8aead06972 Add English to the UI and a profile menu for language and theme
Every UI string now exists in lang/fi and lang/en; a unit test checks that
both languages have the same keys and placeholders. A user's language is
stored on the account (users.locale) and applied by the SetLocale web
middleware, falling back to the session's choice on signed-out pages and
then APP_LOCALE. Emails use the user's language through
HasLocalePreference, and the login page keeps the language after logout.

The header's name, theme toggle and logout button become one profile menu
(a disclosure) with the language buttons, light/dark/system theme radios
kept on the device, and logging out. Signed-out pages get a Suomi/English
switch next to the theme toggle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-25 06:28:39 +02:00

38 lines
1004 B
PHP

<?php
namespace App\Modules\Users\Presentation\Http\Middleware;
use App\Models\User;
use App\Modules\Users\Domain\Enums\Locale;
use Carbon\Carbon;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Symfony\Component\HttpFoundation\Response;
/**
* Sets the language of the user interface: the signed-in user's own choice,
* otherwise the one chosen on the signed-out pages (kept in the session),
* otherwise the application default.
*/
class SetLocale
{
public const SESSION_KEY = 'locale';
public function handle(Request $request, Closure $next): Response
{
$user = $request->user();
$locale = $user instanceof User
? $user->locale
: Locale::tryFrom((string) ($request->hasSession() ? $request->session()->get(self::SESSION_KEY) : ''));
if ($locale !== null) {
App::setLocale($locale->value);
Carbon::setLocale($locale->value);
}
return $next($request);
}
}