diff --git a/src/Symfony/Component/Translation/Tests/TranslatorTest.php b/src/Symfony/Component/Translation/Tests/TranslatorTest.php index 68122b2915..f0d87773ba 100644 --- a/src/Symfony/Component/Translation/Tests/TranslatorTest.php +++ b/src/Symfony/Component/Translation/Tests/TranslatorTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Translation\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Component\Translation\Exception\RuntimeException; use Symfony\Component\Translation\Loader\ArrayLoader; use Symfony\Component\Translation\MessageCatalogue; use Symfony\Component\Translation\Translator; @@ -552,6 +553,16 @@ class TranslatorTest extends TestCase // unchanged if it can't be found $this->assertEquals('some_message2', $translator->transChoice('some_message2', 10, ['%count%' => 10])); } + + public function testMissingLoaderForResourceError() + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('No loader is registered for the "twig" format when loading the "messages.en.twig" resource.'); + + $translator = new Translator('en'); + $translator->addResource('twig', 'messages.en.twig', 'en'); + $translator->getCatalogue('en'); + } } class StringClass diff --git a/src/Symfony/Component/Translation/Translator.php b/src/Symfony/Component/Translation/Translator.php index 1bda62d1b1..131459c6e3 100644 --- a/src/Symfony/Component/Translation/Translator.php +++ b/src/Symfony/Component/Translation/Translator.php @@ -376,7 +376,11 @@ EOF if (isset($this->resources[$locale])) { foreach ($this->resources[$locale] as $resource) { if (!isset($this->loaders[$resource[0]])) { - throw new RuntimeException(sprintf('The "%s" translation loader is not registered.', $resource[0])); + if (\is_string($resource[1])) { + throw new RuntimeException(sprintf('No loader is registered for the "%s" format when loading the "%s" resource.', $resource[0], $resource[1])); + } + + throw new RuntimeException(sprintf('No loader is registered for the "%s" format.', $resource[0])); } $this->catalogues[$locale]->addCatalogue($this->loaders[$resource[0]]->load($resource[1], $locale, $resource[2])); }