Skip to content

Commit

Permalink
Merge branch '5.4' into 6.0
Browse files Browse the repository at this point in the history
* 5.4:
  cs fix
  [Messenger] Fix Doctrine transport on MySQL
  [Filesystem] Remove needless `mb_*` calls
  [Translator] Fix translator overlapse
  [Yaml] Improve test coverage in DumperTest and ParserTest
  Extract dispatching console signal handling and include subscribers
  [Mailer] Fix error message in case of an STMP error
  [HttpClient] Fix shared connections not being freed on PHP < 8
  [HttpFoundation] Fix invalid ID not regenerated with native PHP file sessions
  [HttpClient] Fix memory leak when using StreamWrapper
  minor: fix test
  [Serializer] Fix error message
  remove the ChatterInterface alias when the chatter service is removed
  Bump Symfony version to 5.4.12
  Update VERSION for 5.4.11
  Update CHANGELOG for 5.4.11
  Bump Symfony version to 4.4.45
  Update VERSION for 4.4.44
  Update CONTRIBUTORS for 4.4.44
  Update CHANGELOG for 4.4.44
  • Loading branch information
nicolas-grekas committed Aug 2, 2022
2 parents 55ffbe4 + 42ecc77 commit 5e71973
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
19 changes: 7 additions & 12 deletions MessageCatalogue.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,14 @@ public function replace(array $messages, string $domain = 'messages')
*/
public function add(array $messages, string $domain = 'messages')
{
if (!isset($this->messages[$domain])) {
$this->messages[$domain] = [];
}
$intlDomain = $domain;
if (!str_ends_with($domain, self::INTL_DOMAIN_SUFFIX)) {
$intlDomain .= self::INTL_DOMAIN_SUFFIX;
}
$altDomain = str_ends_with($domain, self::INTL_DOMAIN_SUFFIX) ? substr($domain, 0, -\strlen(self::INTL_DOMAIN_SUFFIX)) : $domain.self::INTL_DOMAIN_SUFFIX;
foreach ($messages as $id => $message) {
if (isset($this->messages[$intlDomain]) && \array_key_exists($id, $this->messages[$intlDomain])) {
$this->messages[$intlDomain][$id] = $message;
} else {
$this->messages[$domain][$id] = $message;
}
unset($this->messages[$altDomain][$id]);
$this->messages[$domain][$id] = $message;
}

if ([] === ($this->messages[$altDomain] ?? null)) {
unset($this->messages[$altDomain]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Catalogue/MergeOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function testGetResultFromIntlDomain()
{
$this->assertEquals(
new MessageCatalogue('en', [
'messages' => ['a' => 'old_a', 'b' => 'old_b'],
'messages' => ['b' => 'old_b'],
'messages+intl-icu' => ['d' => 'old_d', 'c' => 'new_c', 'a' => 'new_a'],
]),
$this->createOperation(
Expand Down
2 changes: 0 additions & 2 deletions Tests/Catalogue/TargetOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public function testGetResultWithMixedDomains()
{
$this->assertEquals(
new MessageCatalogue('en', [
'messages' => ['a' => 'old_a'],
'messages+intl-icu' => ['a' => 'new_a'],
]),
$this->createOperation(
Expand Down Expand Up @@ -103,7 +102,6 @@ public function testGetResultWithMixedDomains()

$this->assertEquals(
new MessageCatalogue('en', [
'messages' => ['a' => 'old_a'],
'messages+intl-icu' => ['b' => 'new_b', 'a' => 'new_a'],
]),
$this->createOperation(
Expand Down
24 changes: 24 additions & 0 deletions Tests/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
use Symfony\Component\Translation\Exception\InvalidArgumentException;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Translation\Exception\RuntimeException;
use Symfony\Component\Translation\Formatter\IntlFormatter;
use Symfony\Component\Translation\Formatter\IntlFormatterInterface;
use Symfony\Component\Translation\Formatter\MessageFormatter;
use Symfony\Component\Translation\Formatter\MessageFormatterInterface;
use Symfony\Component\Translation\Loader\ArrayLoader;
use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Component\Translation\Translator;
Expand Down Expand Up @@ -559,6 +563,26 @@ public function testIntlFormattedDomain()
$this->assertSame('Hi Bob', $translator->trans('some_message', ['%name%' => 'Bob']));
}

public function testIntlDomainOverlapseWithIntlResourceBefore()
{
$intlFormatterMock = $this->createMock(IntlFormatterInterface::class);
$intlFormatterMock->expects($this->once())->method('formatIntl')->with('hello intl', 'en', [])->willReturn('hello intl');

$messageFormatter = new MessageFormatter(null, $intlFormatterMock);

$translator = new Translator('en', $messageFormatter);
$translator->addLoader('array', new ArrayLoader());

$translator->addResource('array', ['some_message' => 'hello intl'], 'en', 'messages+intl-icu');
$translator->addResource('array', ['some_message' => 'hello'], 'en', 'messages');

$this->assertSame('hello', $translator->trans('some_message', [], 'messages'));

$translator->addResource('array', ['some_message' => 'hello intl'], 'en', 'messages+intl-icu');

$this->assertSame('hello intl', $translator->trans('some_message', [], 'messages'));
}

public function testMissingLoaderForResourceError()
{
$this->expectException(RuntimeException::class);
Expand Down

0 comments on commit 5e71973

Please sign in to comment.