Skip to content

Commit

Permalink
Merge pull request #136 from kersysgediminas/empty-string-locale
Browse files Browse the repository at this point in the history
Add failing unit test for empty string locale
  • Loading branch information
gsteel authored Sep 10, 2024
2 parents e1e3126 + 084ec1a commit d553a9c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Translator/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 13 additions & 0 deletions test/Translator/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', ''));
}
}

0 comments on commit d553a9c

Please sign in to comment.