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
@@ -0,0 +1,99 @@
@php
$user = auth()->user();
$currentLocale = app()->getLocale();
@endphp
{{--
The signed-in user's profile menu: a disclosure button (WAI-ARIA disclosure, not role="menu") that opens a panel
with the language (kept on the account), the theme (kept on this device by tallstackui_darkTheme() on <html>,
whose "mode" the radios bind to) and logging out. Escape and a click outside close it, and so does moving focus
out of it. The button's name stays the same; aria-expanded tells whether the panel is open.
--}}
<div
class="relative"
x-data="{ open: false }"
x-on:keydown.escape="if (open) { open = false; $refs.trigger.focus() }"
x-on:click.outside="open = false"
x-on:focusout="if (open && ! $el.contains($event.relatedTarget)) open = false"
>
<button
type="button"
x-ref="trigger"
x-on:click="open = ! open"
x-bind:aria-expanded="open.toString()"
aria-expanded="false"
aria-controls="profile-menu-panel"
aria-label="{{ __('layout.profile.menu', ['name' => $user->name]) }}"
data-profile-menu
class="flex items-center gap-2 rounded-md px-3 py-2 text-sm font-medium text-zinc-200 hover:bg-zinc-700 hover:text-white focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-400"
>
<x-icon name="user-circle" class="size-5" aria-hidden="true" />
<span>{{ $user->name }}</span>
<x-icon name="chevron-down" class="size-4 transition-transform" x-bind:class="{ 'rotate-180': open }" aria-hidden="true" />
</button>
<div
id="profile-menu-panel"
x-show="open"
x-cloak
class="z-40 mt-1 w-72 max-w-[calc(100vw-2rem)] space-y-4 rounded-md border border-zinc-600 bg-zinc-800 p-4 text-sm text-zinc-100 shadow-lg sm:absolute sm:end-0"
>
<p>
<span class="block font-semibold">{{ $user->name }}</span>
<span class="block text-zinc-300">{{ __('users.roles.'.$user->role->value) }}</span>
</p>
<form method="POST" action="{{ route('locale.update') }}">
@csrf
<fieldset>
<legend class="mb-2 font-semibold">{{ __('layout.profile.language') }}</legend>
<div class="flex flex-wrap gap-2">
@foreach (\App\Modules\Users\Domain\Enums\Locale::cases() as $locale)
@php($isCurrent = $locale->value === $currentLocale)
<button
type="submit"
name="locale"
value="{{ $locale->value }}"
lang="{{ $locale->value }}"
aria-pressed="{{ $isCurrent ? 'true' : 'false' }}"
@class([
'flex min-h-6 items-center gap-1 rounded-md border px-3 py-1.5 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-400',
'border-zinc-200 bg-zinc-700 font-semibold text-white' => $isCurrent,
'border-zinc-500 text-zinc-200 hover:bg-zinc-700 hover:text-white' => ! $isCurrent,
])
>
@if ($isCurrent)
<x-icon name="check" class="size-4" aria-hidden="true" />
@endif
{{ $locale->nativeName() }}
</button>
@endforeach
</div>
</fieldset>
</form>
<fieldset>
<legend class="mb-2 font-semibold">{{ __('layout.profile.theme') }}</legend>
<div class="space-y-1">
@foreach (['light' => 'theme_light', 'dark' => 'theme_dark', 'system' => 'theme_system'] as $mode => $label)
<label class="flex min-h-6 cursor-pointer items-center gap-2">
<input
type="radio"
name="profile-theme"
value="{{ $mode }}"
x-model="mode"
data-theme-option="{{ $mode }}"
class="size-4 border-zinc-400 bg-zinc-900 text-primary-400 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-400 focus:ring-0 focus:ring-offset-0"
>
{{ __('layout.profile.'.$label) }}
</label>
@endforeach
</div>
</fieldset>
<form method="POST" action="{{ route('logout') }}" class="border-t border-zinc-600 pt-3">
@csrf
<x-button submit subtle color="black" sm icon="arrow-right-start-on-rectangle" :text="__('layout.logout')" />
</form>
</div>
</div>
+4 -12
View File
@@ -60,22 +60,14 @@
@endforeach
</nav>
<div class="flex flex-wrap items-center gap-3">
<span class="text-sm text-zinc-300">{{ __('layout.signed_in_as', ['name' => auth()->user()->name]) }}</span>
@include('partials.theme-toggle')
<form method="POST" action="{{ route('logout') }}">
@csrf
<x-button submit subtle color="black" sm icon="arrow-right-start-on-rectangle" :text="__('layout.logout')" />
</form>
</div>
<x-profile-menu />
</div>
</header>
@else
<div class="flex justify-end px-4 pt-3 sm:px-6">
<header class="flex items-center justify-end gap-3 px-4 pt-3 sm:px-6">
@include('partials.locale-switch')
@include('partials.theme-toggle')
</div>
</header>
@endauth
<main id="main-content" tabindex="-1" class="focus:outline-none">
+10 -6
View File
@@ -1,9 +1,8 @@
<?php
use Livewire\Attributes\Title;
use Livewire\Component;
new #[Title('Toiminnanohjaus')] class extends Component
new class extends Component
{
public int $clickCount = 0;
@@ -11,17 +10,22 @@ new #[Title('Toiminnanohjaus')] class extends Component
{
$this->clickCount++;
}
public function render(): mixed
{
return $this->view()->title(__('layout.demo.title'));
}
};
?>
<div class="mx-auto max-w-xl space-y-6 p-6">
<h1 class="text-2xl font-semibold">Toiminnanohjaus</h1>
<h1 class="text-2xl font-semibold">{{ __('layout.demo.title') }}</h1>
<p class="text-sm text-zinc-600 dark:text-zinc-300">Livewire ja TallStackUI toimivat. Tämä on väliaikainen kokeilusivu.</p>
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('layout.demo.intro') }}</p>
<x-button icon="plus" wire:click="incrementClickCount" text="Lisää klikkaus" />
<x-button icon="plus" wire:click="incrementClickCount" :text="__('layout.demo.add_click')" />
<p role="status" aria-live="polite" aria-atomic="true" class="text-sm">
Klikattu {{ $clickCount }} kertaa
{{ __('layout.demo.clicked', ['count' => $clickCount]) }}
</p>
</div>
@@ -0,0 +1,31 @@
{{--
Language choice on the signed-out pages (login, forgot and set password). It is kept in the session; once
signed in, the account's own language is used. The current language is marked with aria-pressed and a check
icon, not colour alone.
--}}
<form method="POST" action="{{ route('locale.update') }}">
@csrf
<fieldset class="flex items-center gap-1">
<legend class="sr-only">{{ __('layout.profile.language') }}</legend>
@foreach (\App\Modules\Users\Domain\Enums\Locale::cases() as $locale)
@php($isCurrent = $locale->value === app()->getLocale())
<button
type="submit"
name="locale"
value="{{ $locale->value }}"
lang="{{ $locale->value }}"
aria-pressed="{{ $isCurrent ? 'true' : 'false' }}"
@class([
'flex min-h-6 items-center gap-1 rounded-md px-2 py-1 text-sm focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:focus-visible:outline-blue-400',
'font-semibold text-zinc-900 underline decoration-2 underline-offset-4 dark:text-white' => $isCurrent,
'text-zinc-700 hover:bg-zinc-200 dark:text-zinc-200 dark:hover:bg-zinc-700' => ! $isCurrent,
])
>
@if ($isCurrent)
<x-icon name="check" class="size-4" aria-hidden="true" />
@endif
{{ $locale->nativeName() }}
</button>
@endforeach
</fieldset>
</form>