[Translation] prefer intl domain when adding messages to catalogue
This commit is contained in:
parent
be84687263
commit
b72b7d3413
@ -158,9 +158,17 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
public function add($messages, $domain = 'messages')
|
||||
{
|
||||
if (!isset($this->messages[$domain])) {
|
||||
$this->messages[$domain] = $messages;
|
||||
} else {
|
||||
foreach ($messages as $id => $message) {
|
||||
$this->messages[$domain] = [];
|
||||
}
|
||||
$intlDomain = $domain;
|
||||
$suffixLength = \strlen(self::INTL_DOMAIN_SUFFIX);
|
||||
if (\strlen($domain) > $suffixLength && false !== strpos($domain, self::INTL_DOMAIN_SUFFIX, -$suffixLength)) {
|
||||
$intlDomain .= self::INTL_DOMAIN_SUFFIX;
|
||||
}
|
||||
foreach ($messages as $id => $message) {
|
||||
if (isset($this->messages[$intlDomain]) && \array_key_exists($id, $this->messages[$intlDomain])) {
|
||||
$this->messages[$intlDomain][$id] = $message;
|
||||
} else {
|
||||
$this->messages[$domain][$id] = $message;
|
||||
}
|
||||
}
|
||||
|
@ -67,6 +67,19 @@ class TargetOperationTest extends AbstractOperationTest
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetResultWithMixedDomains()
|
||||
{
|
||||
$this->assertEquals(
|
||||
new MessageCatalogue('en', [
|
||||
'messages+intl-icu' => ['a' => 'old_a'],
|
||||
]),
|
||||
$this->createOperation(
|
||||
new MessageCatalogue('en', ['messages' => ['a' => 'old_a']]),
|
||||
new MessageCatalogue('en', ['messages+intl-icu' => ['a' => 'new_a']])
|
||||
)->getResult()
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetResultWithMetadata()
|
||||
{
|
||||
$leftCatalogue = new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b']]);
|
||||
|
Reference in New Issue
Block a user