A language picked on a signed-out page is now stored on the account when the user signs in (StoreLocaleChosenBeforeLogin), so the app does not switch back to the account default. EnsureAccountIsUsable keeps the user's language for the login page when it ends a disabled account's session. ChangePreferredLocale runs in a transaction like the other use cases, the language names come from layout.languages instead of the Locale enum, and the translation test also compares fi.json with en.json and rejects English files without a Finnish counterpart. Co-Authored-By: Claude Opus 5.5 <[email protected]>
28 lines
806 B
PHP
28 lines
806 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Users\Application\UseCases;
|
|
|
|
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
|
use App\Modules\Users\Domain\Contracts\UserAccountRepository;
|
|
use App\Modules\Users\Domain\Enums\Locale;
|
|
|
|
/**
|
|
* A user chooses the language of the user interface: from their profile menu,
|
|
* or on the signed-out pages before signing in. The choice is kept on the
|
|
* account, so it follows them to every device.
|
|
*/
|
|
final class ChangePreferredLocale
|
|
{
|
|
public function __construct(
|
|
private UserAccountRepository $users,
|
|
private TransactionManager $transactions,
|
|
) {}
|
|
|
|
public function execute(int $userId, Locale $locale): void
|
|
{
|
|
$this->transactions->run(fn () => $this->users->changeLocale($userId, $locale));
|
|
}
|
|
}
|