diff --git a/src/Translator/Translator.php b/src/Translator/Translator.php index 597d2395..598686a9 100644 --- a/src/Translator/Translator.php +++ b/src/Translator/Translator.php @@ -345,6 +345,7 @@ public function getPluginManager() */ public function translate($message, $textDomain = 'default', $locale = null) { + $locale = $locale === '' ? null : $locale; $locale = $locale ?? $this->getLocale(); $translation = $this->getTranslatedMessage($message, $locale, $textDomain); diff --git a/test/Translator/TranslatorTest.php b/test/Translator/TranslatorTest.php index 768c2ac6..c865581f 100644 --- a/test/Translator/TranslatorTest.php +++ b/test/Translator/TranslatorTest.php @@ -549,4 +549,17 @@ public function testNullMessageArgumentShouldReturnAnEmptyString(): void self::assertEquals('', $this->translator->translate(null)); } + + public function testTranslateWithEmptyStringLocale(): void + { + $this->translator->setLocale('en_US'); + $this->translator->addTranslationFile( + 'phparray', + $this->testFilesDir . '/testarray/translation-more-en_US.php', + 'default', + 'en_US' + ); + + self::assertEquals('Message 8 (en)', $this->translator->translate('Message 8', 'default', '')); + } }