Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Translator/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,9 @@ protected function loadMessages($textDomain, $locale)
|| $this->loadMessagesFromFiles($textDomain, $locale)
);

if ($messagesLoaded && $cache !== null) {
if (!$messagesLoaded) {
$this->messages[$textDomain][$locale] = null;
} elseif ($cache !== null) {
$cache->setItem($cacheId, $this->messages[$textDomain][$locale]);
}
}
Expand Down
21 changes: 21 additions & 0 deletions test/Translator/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,25 @@ public function testTranslatePlurals()
$this->assertEquals('Message 5 (en) Plural 1', $pl1);
$this->assertEquals('Message 5 (en) Plural 2', $pl2);
}

public function testTranslateNonExistantLocale()
{
$this->translator->addTranslationFilePattern(
'phparray',
$this->testFilesDir . '/testarray',
'translation-%s.php'
);

// Test that a locale without translations does not cause warnings

$this->translator->setLocale('es_ES');

$this->assertEquals('Message 1', $this->translator->translate('Message 1'));
$this->assertEquals('Message 9', $this->translator->translate('Message 9'));

$this->translator->setLocale('fr_FR');

$this->assertEquals('Message 1', $this->translator->translate('Message 1'));
$this->assertEquals('Message 9', $this->translator->translate('Message 9'));
}
}

0 comments on commit 9092473

Please sign in to comment.