embed resource name in error message
This commit is contained in:
parent
1e1060f2eb
commit
507a5963e4
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\Translation\Tests;
|
namespace Symfony\Component\Translation\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\Translation\Exception\RuntimeException;
|
||||||
use Symfony\Component\Translation\Loader\ArrayLoader;
|
use Symfony\Component\Translation\Loader\ArrayLoader;
|
||||||
use Symfony\Component\Translation\MessageCatalogue;
|
use Symfony\Component\Translation\MessageCatalogue;
|
||||||
use Symfony\Component\Translation\Translator;
|
use Symfony\Component\Translation\Translator;
|
||||||
@ -552,6 +553,16 @@ class TranslatorTest extends TestCase
|
|||||||
// unchanged if it can't be found
|
// unchanged if it can't be found
|
||||||
$this->assertEquals('some_message2', $translator->transChoice('some_message2', 10, ['%count%' => 10]));
|
$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
|
class StringClass
|
||||||
|
@ -376,7 +376,11 @@ EOF
|
|||||||
if (isset($this->resources[$locale])) {
|
if (isset($this->resources[$locale])) {
|
||||||
foreach ($this->resources[$locale] as $resource) {
|
foreach ($this->resources[$locale] as $resource) {
|
||||||
if (!isset($this->loaders[$resource[0]])) {
|
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]));
|
$this->catalogues[$locale]->addCatalogue($this->loaders[$resource[0]]->load($resource[1], $locale, $resource[2]));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user