minor #36780 [Translator] embed resource name in error message (xabbuh)
This PR was merged into the 3.4 branch.
Discussion
----------
[Translator] embed resource name in error message
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | no
| New feature? | no
| Deprecations? | no
| Tickets |
| License | MIT
| Doc PR |
Someone reported on Slack that they accidentally stored a translation file with the `.twig` extension and that the error message was quite confusing.
Commits
-------
507a5963e4
embed resource name in error message
This commit is contained in:
commit
cec0dfe5b3
@ -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
|
||||
|
@ -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]));
|
||||
}
|
||||
|
Reference in New Issue
Block a user