8000 embed resource name in error message · symfony/symfony@507a596 · GitHub
[go: up one dir, main page]

Skip to content

Commit 507a596

Browse files
committed
embed resource name in error message
1 parent 1e1060f commit 507a596

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Symfony/Component/Translation/Tests/TranslatorTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Translation\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Translation\Exception\RuntimeException;
1516
use Symfony\Component\Translation\Loader\ArrayLoader;
1617
use Symfony\Component\Translation\MessageCatalogue;
1718
use Symfony\Component\Translation\Translator;
@@ -552,6 +553,16 @@ public function testTransChoiceFallbackWithNoTranslation()
552553
// unchanged if it can't be found
553554
$this->assertEquals('some_message2', $translator->transChoice('some_message2', 10, ['%count%' => 10]));
554555
}
556+
557+
public function testMissingLoaderForResourceError()
558+
{
559+
$this->expectException(RuntimeException::class);
560+
$this->expectExceptionMessage('No loader is registered for the "twig" format when loading the "messages.en.twig" resource.');
561+
562+
$translator = new Translator('en');
563+
$translator->addResource('twig', 'messages.en.twig', 'en');
564+
$translator->getCatalogue('en');
565+
}
555566
}
556567

557568
class StringClass

src/Symfony/Component/Translation/Translator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,11 @@ private function doLoadCatalogue($locale)
376376
if (isset($this->resources[$locale])) {
377377
foreach ($this->resources[$locale] as $resource) {
378378
if (!isset($this->loaders[$resource[0]])) {
379-
throw new RuntimeException(sprintf('The "%s" translation loader is not registered.', $resource[0]));
379+
if (\is_string($resource[1])) {
380+
throw new RuntimeException(sprintf('No loader is registered for the "%s" format when loading the "%s" resource.', $resource[0], $resource[1]));
381+
}
382+
383+
throw new RuntimeException(sprintf('No loader is registered for the "%s" format.', $resource[0]));
380384
}
381385
$this->catalogues[$locale]->addCatalogue($this->loaders[$resource[0]]->load($resource[1], $locale, $resource[2]));
382386
}

0 commit comments

Comments
 (0)
0