[Translation] Fix for translation:update command updating ICU messages
This commit is contained in:
parent
f8d3b0626a
commit
567cee5f02
@ -356,7 +356,14 @@ EOF
|
||||
{
|
||||
$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) {
|
||||
|
@ -72,6 +72,11 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
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] ?? []);
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,30 @@ class MessageCatalogueTest extends TestCase
|
||||
$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']]);
|
||||
|
Reference in New Issue
Block a user