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]>
This commit is contained in:
2026-11-25 06:28:39 +02:00
co-authored by Claude Opus 5.5
parent c2265256c3
commit 8aead06972
40 changed files with 2197 additions and 44 deletions
+2 -2
View File
@@ -17,8 +17,8 @@ it('renders the home page with the main menu', function () {
->assertSee('Siirry pääsisältöön')
->assertSee('id="main-content"', false)
->assertSee('aria-label="Päävalikko"', false)
->assertSee('Kirjautuneena: Eero Esimerkki')
->assertSee('aria-label="Tumma teema"', false);
->assertSee('aria-label="Profiili: Eero Esimerkki"', false)
->assertSee('Kirjaudu ulos');
});
it('increments the click count', function () {
@@ -0,0 +1,75 @@
<?php
use App\Models\User;
use App\Modules\Users\Domain\Enums\Locale;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
uses(RefreshDatabase::class);
it('stores the language a signed-in user chooses and shows the pages in it', function () {
$user = User::factory()->create(['name' => 'Eero Esimerkki']);
$this->actingAs($user)
->from(route('home'))
->post(route('locale.update'), ['locale' => 'en'])
->assertRedirect(route('home'));
expect($user->fresh()->locale)->toBe(Locale::English);
// A new request loads the user again from the database.
$this->actingAs($user->fresh())
->get(route('home'))
->assertOk()
->assertSee('lang="en"', false)
->assertSee('Sign out');
});
it('keeps the language chosen on the signed-out pages in the session', function () {
$this->from(route('login'))
->post(route('locale.update'), ['locale' => 'en'])
->assertRedirect(route('login'))
->assertSessionHas('locale', 'en');
$this->get(route('login'))
->assertOk()
->assertSee('lang="en"', false);
});
it('uses the account language over the one in the session', function () {
$user = User::factory()->create(['locale' => 'fi']);
$this->actingAs($user)
->withSession(['locale' => 'en'])
->get(route('home'))
->assertSee('lang="fi"', false)
->assertSee('Kirjaudu ulos');
});
it('keeps the language on the login page after logging out', function () {
$user = User::factory()->create(['locale' => 'en']);
$this->actingAs($user)->post(route('logout'))->assertSessionHas('locale', 'en');
});
it('rejects an unknown language', function () {
$user = User::factory()->create();
$this->actingAs($user)
->post(route('locale.update'), ['locale' => 'sv'])
->assertSessionHasErrors('locale');
expect($user->fresh()->locale)->toBe(Locale::Finnish);
});
it('sends the set-password email in the language of the user', function () {
Notification::fake();
$user = User::factory()->create(['locale' => 'en']);
$user->notify(new ResetPassword('token'));
Notification::assertSentTo($user, ResetPassword::class, function (ResetPassword $notification, array $channels, User $notifiable, ?string $locale) {
return $locale === 'en';
});
});