Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 44fd6d0

Browse files
author
Xavier RENAUDIN
committed
[Translator] Fix translator overlapse
1 parent 18f3978 commit 44fd6d0

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
use Symfony\Component\Translation\Exception\InvalidArgumentException;
1616
use Symfony\Component\Translation\Exception\NotFoundResourceException;
1717
use Symfony\Component\Translation\Exception\RuntimeException;
18+
use Symfony\Component\Translation\Formatter\IntlFormatter;
19+
use Symfony\Component\Translation\Formatter\IntlFormatterInterface;
20+
use Symfony\Component\Translation\Formatter\MessageFormatter;
21+
use Symfony\Component\Translation\Formatter\MessageFormatterInterface;
1822
use Symfony\Component\Translation\Loader\ArrayLoader;
1923
use Symfony\Component\Translation\MessageCatalogue;
2024
use Symfony\Component\Translation\Translator;
@@ -683,6 +687,41 @@ public function testIntlFormattedDomain()
683687
$this->assertSame('Hi Bob', $translator->trans('some_message', ['%name%' => 'Bob']));
684688
}
685689

690+
public function testIntlDomainOverlapseWithLegacyResourceBefore()
691+
{
692+
$intlFormatterMock = $this->createMock(IntlFormatterInterface::class);
693+
$intlFormatterMock->expects($this->once())->method('formatIntl')->with('hello intl', 'en', [])->willReturn('hello intl');
694+
695+
$messageFormatter = new MessageFormatter(null, $intlFormatterMock);
696+
697+
$translator = new Translator('en', $messageFormatter);
698+
$translator->addLoader('array', new ArrayLoader());
699+
700+
$translator->addResource('array', ['some_message' => 'hello'], 'en', 'messages');
701+
$translator->addResource('array', ['some_message' => 'hello intl'], 'en', 'messages+intl-icu');
702+
703+
$this->assertSame('hello intl', $translator->trans('some_message', [], 'messages'));
704+
}
705+
706+
/**
707+
* This is currently symfony application execution order
708+
*/
709+
public function testIntlDomainOverlapseWithIntlResourceBefore()
710+
{
711+
$intlFormatterMock = $this->createMock(IntlFormatterInterface::class);
712+
$intlFormatterMock->expects($this->once())->method('formatIntl')->with('hello intl', 'en', [])->willReturn('hello intl');
713+
714+
$messageFormatter = new MessageFormatter(null, $intlFormatterMock);
715+
716+
$translator = new Translator('en', $messageFormatter);
717+
$translator->addLoader('array', new ArrayLoader());
718+
719+
$translator->addResource('array', ['some_message' => 'hello intl'], 'en', 'messages+intl-icu');
720+
$translator->addResource('array', ['some_message' => 'hello'], 'en', 'messages');
721+
722+
$this->assertSame('hello intl', $translator->trans('some_message', [], 'messages'));
723+
}
724+
686725
/**
687726
* @group legacy
688727
*/

0 commit comments

Comments
 (0)