8000 changes MessageCatalogue.php to returns intl-icu messages only if req… · symfony/symfony@b4478f3 · GitHub
[go: up one dir, main page]

Skip to content

Commit b4478f3

Browse files
committed
changes MessageCatalogue.php to returns intl-icu messages only if requested
reverted MessageCatalogueInterface.php to initial version to keep BC
1 parent fecc728 commit b4478f3

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
317317
private function filterCatalogue(MessageCatalogue $catalogue, string $domain): MessageCatalogue
318318
{
319319
$filteredCatalogue = new MessageCatalogue($catalogue->getLocale());
320-
$intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX;
321320

322-
if ($intlMessages = $catalogue->all($intlDomain, true)) {
321+
// extract intl-icu messages only
322+
$intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX;
323+
if ($intlMessages = $catalogue->all($intlDomain)) {
323324
$filteredCatalogue->add($intlMessages, $intlDomain);
324325
}
325-
if ($messages = $catalogue->all($domain, true)) {
326+
327+
// extract all messages and subtract intl-icu messages
328+
if ($messages = array_diff($catalogue->all($domain), $intlMessages)) {
326329
$filteredCatalogue->add($messages, $domain);
327330
}
328331
foreach ($catalogue->getResources() as $resource) {

src/Symfony/Component/Translation/MessageCatalogue.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,16 @@ public function getDomains()
6565
/**
6666
* {@inheritdoc}
6767
*/
68-
public function all(string $domain = null, $strict = false)
68+
public function all(string $domain = null)
6969
{
7070
if (null !== $domain) {
71-
if ($strict) {
71+
72+
// skip messages merge if intl-icu requested explicitly
73+
if (false !== strpos($domain, self::INTL_DOMAIN_SUFFIX)) {
7274
return $this->messages[$domain] ?? [];
73-
} else {
74-
return ($this->messages[$domain.self::INTL_DOMAIN_SUFFIX] ?? []) + ($this->messages[$domain] ?? []);
7575
}
76+
77+
return ($this->messages[$domain.self::INTL_DOMAIN_SUFFIX] ?? []) + ($this->messages[$domain] ?? []);
7678
}
7779

7880
$allMessages = [];

src/Symfony/Component/Translation/MessageCatalogueInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ public function getDomains();
4242
* If $domain is null, it returns all messages.
4343
*
4444
* @param string $domain The domain name
45-
* @param bool $strict - return messages for defined domain only
4645
*
4746
* @return array An array of messages
4847
*/
49-
public function all(string $domain = null, $strict = false);
48+
public function all(string $domain = null);
5049

5150
/**
5251
* Sets a message translation.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public function testAll()
3939
$this->assertEquals($messages, $catalogue->all());
4040

4141
$messages = ['domain1+intl-icu' => ['foo' => 'bar']] + $messages + [
42-
'domain2+intl-icu' => ['bar' => 'foo'],
43-
'domain3+intl-icu' => ['biz' => 'biz'],
44-
];
42+
'domain2+intl-icu' => ['bar' => 'foo'],
43+
'domain3+intl-icu' => ['biz' => 'biz'],
44+
];
4545
$catalogue = new MessageCatalogue('en', $messages);
4646

4747
$this->assertEquals(['foo' => 'bar'], $catalogue->all('domain1'));
@@ -69,13 +69,13 @@ public function testAllIntICU()
6969
$catalogue = new MessageCatalogue('en', $messages);
7070

7171
// separated domains
72-
$this->assertEquals(['foo' => 'bar'], $catalogue->all('domain1+intl-icu', true));
73-
$this->assertEquals(['bar' => 'foo'], $catalogue->all('domain2+intl-icu', true));
74-
$this->assertEquals(['biz' => 'biz'], $catalogue->all('domain2', true));
72+
$this->assertEquals(['foo' => 'bar'], $catalogue->all('domain1+intl-icu'));
73+
$this->assertEquals(['bar' => 'foo'], $catalogue->all('domain2+intl-icu'));
7574

7675
// merged, intl-icu ignored
7776
$this->assertEquals(['bar' => 'foo', 'biz' => 'biz'], $catalogue->all('domain2'));
7877

78+
// intl-icu ignored
7979
$messagesExpected = [
8080
'domain1' => ['foo' => 'bar'],
8181
'domain2' => ['bar' => 'foo', 'biz' => 'biz'],

0 commit comments

Comments
 (0)
0