From 71af55abcf066811056891835f41b0fbb98a9964 Mon Sep 17 00:00:00 2001 From: jordyvanderhaegen Date: Wed, 27 Nov 2024 22:04:44 +0100 Subject: [PATCH] fix: custom translator not receiving updated locale --- .../LaravelLocalization.php | 1 + tests/CustomTranslatorTest.php | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/CustomTranslatorTest.php diff --git a/src/Mcamara/LaravelLocalization/LaravelLocalization.php b/src/Mcamara/LaravelLocalization/LaravelLocalization.php index 228ece5..7052929 100644 --- a/src/Mcamara/LaravelLocalization/LaravelLocalization.php +++ b/src/Mcamara/LaravelLocalization/LaravelLocalization.php @@ -194,6 +194,7 @@ public function setLocale($locale = null) } $this->app->setLocale($this->currentLocale); + $this->translator->setLocale($this->currentLocale); // Regional locale such as de_DE, so formatLocalized works in Carbon $regional = $this->getCurrentLocaleRegional(); diff --git a/tests/CustomTranslatorTest.php b/tests/CustomTranslatorTest.php new file mode 100644 index 0000000..8bb7f1e --- /dev/null +++ b/tests/CustomTranslatorTest.php @@ -0,0 +1,33 @@ +app, + $this->app['config'], + $translator, + $this->app['router'], + $this->app['request'], + $this->app['url'] + ); + + $localization->setLocale('es'); + + $this->assertEquals('es', $translator->getLocale()); + } +}