8000 [Translator] Fix translator overlapse · symfony/symfony@361394e · GitHub
[go: up one dir, main page]

Skip to content

Commit 361394e

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

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
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
*/

src/Symfony/Component/Translation/Translator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public function trans($id, array $parameters = [], $domain = null, $locale = nul
232232
}
233233

234234
if ($this->hasIntlFormatter && $catalogue->defines($id, $domain.MessageCatalogue::INTL_DOMAIN_SUFFIX)) {
235-
return $this->formatter->formatIntl($catalogue->get($id, $domain), $locale, $parameters);
235+
return $this->formatter->formatIntl($catalogue->get($id, $domain.MessageCatalogue::INTL_DOMAIN_SUFFIX), $locale, $parameters);
236236
}
237237

238238
return $this->formatter->format($catalogue->get($id, $domain), $locale, $parameters);

0 commit comments

Comments
 (0)
0