From 7dab106f063b2e1e9e0dbfc50e4bdc9c56030e0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulo=20S=C3=A9rgio=20Dantas?= Date: Wed, 1 Jul 2026 13:49:48 -0300 Subject: [PATCH] fix(workspace): default content_language to the app locale, not 'en' When a workspace is created without an explicit content_language, `data_get($data, 'content_language')` returns null, array_filter drops the key, and the column falls back to its DB default of 'en'. So AI content and notifications came out in English even when the app was running in another locale. Default to `app()->getLocale()` instead, so a new workspace inherits the user's current language. An explicit content_language still wins. --- app/Actions/Workspace/CreateWorkspace.php | 2 +- .../Actions/Workspace/CreateWorkspaceTest.php | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/Actions/Workspace/CreateWorkspace.php b/app/Actions/Workspace/CreateWorkspace.php index 4c42fe67..3c7c2df0 100644 --- a/app/Actions/Workspace/CreateWorkspace.php +++ b/app/Actions/Workspace/CreateWorkspace.php @@ -24,7 +24,7 @@ public static function execute(User $user, array $data): Workspace 'brand_color' => data_get($data, 'brand_color'), 'background_color' => data_get($data, 'background_color'), 'text_color' => data_get($data, 'text_color'), - 'content_language' => data_get($data, 'content_language'), + 'content_language' => data_get($data, 'content_language', app()->getLocale()), ], static fn ($value): bool => $value !== null); $workspace = DB::transaction(function () use ($user, $attributes): Workspace { diff --git a/tests/Feature/Actions/Workspace/CreateWorkspaceTest.php b/tests/Feature/Actions/Workspace/CreateWorkspaceTest.php index a31bf419..7c57efd3 100644 --- a/tests/Feature/Actions/Workspace/CreateWorkspaceTest.php +++ b/tests/Feature/Actions/Workspace/CreateWorkspaceTest.php @@ -42,6 +42,28 @@ expect($member?->pivot->role)->toBe(Role::Admin->value); }); +test('CreateWorkspace inherits the app locale as content_language when none is given', function () { + app()->setLocale('pt-BR'); + + $account = Account::factory()->create(); + $user = User::factory()->create(['account_id' => $account->id]); + + $workspace = CreateWorkspace::execute($user, ['name' => 'Acme']); + + expect($workspace->content_language)->toBe('pt-BR'); +}); + +test('CreateWorkspace keeps an explicit content_language over the app locale', function () { + app()->setLocale('pt-BR'); + + $account = Account::factory()->create(); + $user = User::factory()->create(['account_id' => $account->id]); + + $workspace = CreateWorkspace::execute($user, ['name' => 'Acme', 'content_language' => 'es']); + + expect($workspace->content_language)->toBe('es'); +}); + test('CreateWorkspace ignores unknown extra keys like logo_url', function () { $account = Account::factory()->create(); $user = User::factory()->create(['account_id' => $account->id]);