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
+23 -2
View File
@@ -3,10 +3,12 @@
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Modules\Users\Domain\Enums\Locale;
use App\Modules\Users\Domain\Enums\MoneyPermission;
use App\Modules\Users\Domain\Enums\Role;
use App\Modules\Users\Infrastructure\Persistence\Eloquent\UserMoneyPermissionsModel;
use Database\Factories\UserFactory;
use Illuminate\Contracts\Translation\HasLocalePreference;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -27,15 +29,25 @@ use Illuminate\Support\Carbon;
* @property bool $is_active
* @property Carbon|null $employment_ends_on
* @property int|null $supervisor_id
* @property Locale $locale
* @property-read UserMoneyPermissionsModel|null $moneyPermissions
*/
#[Fillable(['name', 'email', 'password', 'role', 'is_active', 'employment_ends_on', 'supervisor_id'])]
#[Fillable(['name', 'email', 'password', 'role', 'is_active', 'employment_ends_on', 'supervisor_id', 'locale'])]
#[Hidden(['password', 'remember_token'])]
class User extends Authenticatable
class User extends Authenticatable implements HasLocalePreference
{
/** @use HasFactory<UserFactory> */
use HasFactory, Notifiable;
/**
* The column defaults, so a user made in this request has them too.
*
* @var array<string, mixed>
*/
protected $attributes = [
'locale' => 'fi',
];
/**
* @return BelongsTo<User, $this>
*/
@@ -66,6 +78,14 @@ class User extends Authenticatable
&& ($this->moneyPermissions?->allows($permission) ?? false);
}
/**
* The language of the user's emails, such as the set-password link.
*/
public function preferredLocale(): string
{
return $this->locale->value;
}
/**
* Get the attributes that should be cast.
*
@@ -79,6 +99,7 @@ class User extends Authenticatable
'role' => Role::class,
'is_active' => 'boolean',
'employment_ends_on' => 'date',
'locale' => Locale::class,
];
}
}