8000 [Translation] Fix for translation:update command updating ICU messages by artemoliynyk · Pull Request #36505 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Translation] Fix for translation:update command updating ICU messages #36505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Translation] Fix for translation:update command updating ICU messages
  • Loading branch information
artemoliynyk authored and nicolas-grekas committed Apr 30, 2020
commit 567cee5f02d16ec4af270c71bfd2efc661fee424
10000
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,14 @@ private function filterCatalogue(MessageCatalogue $catalogue, string $domain): M
{
$filteredCatalogue = new MessageCatalogue($catalogue->getLocale());

if ($messages = $catalogue->all($domain)) {
// extract intl-icu messages only
$intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX;
if ($intlMessages = $catalogue->all($intlDomain)) {
$filteredCatalogue->add($intlMessages, $intlDomain);
}

// extract all messages and subtract intl-icu messages
if ($messages = array_diff($catalogue->all($domain), $intlMessages)) {
$filteredCatalogue->add($messages, $domain);
}
foreach ($catalogue->getResources() as $resource) {
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Translation/MessageCatalogue.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public function getDomains()
public function all($domain = null)
{
if (null !== $domain) {
// skip messages merge if intl-icu requested explicitly
if (false !== strpos($domain, self::INTL_DOMAIN_SUFFIX)) {
return $this->messages[$domain] ?? [];
}

return ($this->messages[$domain.self::INTL_DOMAIN_SUFFIX] ?? []) + ($this->messages[$domain] ?? []);
}

Expand Down
24 changes: 24 additions & 0 deletions src/Symfony/Component/Translation/Tests/MessageCatalogueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ public function testAll()
$this->assertEquals($messages, $catalogue->all());
}

public function testAllIntICU()
{
$messages = [
'domain1+intl-icu' => ['foo' => 'bar'],
'domain2+intl-icu' => ['bar' => 'foo'],
'domain2' => ['biz' => 'biz'],
];
$catalogue = new MessageCatalogue('en', $messages);

// separated domains
$this->assertSame(['foo' => 'bar'], $catalogue->all('domain1+intl-icu'));
$this->assertSame(['bar' => 'foo'], $catalogue->all('domain2+intl-icu'));

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

// intl-icu ignored
$messagesExpected = [
'domain1' => ['foo' => 'bar'],
'domain2' => ['bar' => 'foo', 'biz' => 'biz'],
];
$this->assertSame($messagesExpected, $catalogue->all());
}

public function testHas()
{
$catalogue = new MessageCatalogue('en', ['domain1' => ['foo' => 'foo'], 'domain2+intl-icu' => ['bar' => 'bar']]);
Expand Down
0