From fc5f978d4615da171e89ca0b2febc5cf7289e027 Mon Sep 17 00:00:00 2001 From: Jordy Van der Haegen Date: Sun, 26 Apr 2026 15:12:58 +0200 Subject: [PATCH] Allow null in setLocale to reset to app locale Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/UnderscoreTranslatable.php | 2 +- tests/UnderscoreTranslatableTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/UnderscoreTranslatable.php b/src/UnderscoreTranslatable.php index 8d546a7..8b2835d 100644 --- a/src/UnderscoreTranslatable.php +++ b/src/UnderscoreTranslatable.php @@ -8,7 +8,7 @@ trait UnderscoreTranslatable { protected ?string $translationLocale = null; - public function setLocale(string $locale): self + public function setLocale(?string $locale): self { $this->translationLocale = $locale; diff --git a/tests/UnderscoreTranslatableTest.php b/tests/UnderscoreTranslatableTest.php index 113cd7b..de9d6b2 100644 --- a/tests/UnderscoreTranslatableTest.php +++ b/tests/UnderscoreTranslatableTest.php @@ -21,6 +21,19 @@ public function it_can_set_and_get_the_translation_locale(): void $this->assertEquals('nl', $post->getLocale()); } + #[Test] + public function it_can_reset_the_translation_locale_by_passing_null(): void + { + config(['app.locale' => 'en']); + + $post = new Post(); + $post->setLocale('nl'); + $this->assertEquals('nl', $post->getLocale()); + + $post->setLocale(null); + $this->assertEquals('en', $post->getLocale()); + } + #[Test] public function it_can_check_if_an_attribute_is_translatable(): void {