Skip to content

Commit

Permalink
Merge branch '5.0'
Browse files Browse the repository at this point in the history
* 5.0:
  [VarDumper] fix for change in PHP 7.4.6
  Added regression test for AccountStatusException behavior (ref #36822)
  [HttpClient] fix PHP warning + accept status code >= 600
  [Security/Core] fix compat of `NativePasswordEncoder` with pre-PHP74 values of `PASSWORD_*` consts
  embed resource name in error message
  [FrameworkBundle] fix stringable annotation
  Change priority of KernelEvents::RESPONSE subscriber
  Fix register event listeners compiler pass
  Missing description in `messenger:setup-transports` command
  [Serializer] fix issue with PHP 8
  [WebProfiler] Remove 'none' when appending CSP tokens
  [TwigBundle] FormExtension does not have a constructor anymore since sf 4.0
  [Yaml] Fix escaped quotes in quoted multi-line string
  • Loading branch information
nicolas-grekas committed May 16, 2020
2 parents 3a5c9de + e466c71 commit 4880865
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Tests/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -513,6 +514,16 @@ public function testIntlFormattedDomain()
$translator->addResource('array', ['some_message' => 'Hi {name}'], 'en', 'messages+intl-icu');
$this->assertSame('Hi Bob', $translator->trans('some_message', ['%name%' => 'Bob']));
}

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
Expand Down
6 changes: 5 additions & 1 deletion Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,11 @@ protected function doLoadCatalogue(string $locale): void
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]));
}
Expand Down

0 comments on commit 4880865

Please sign in to comment.