[translation] Fix update existing key with existing +int-icu domain

This commit is contained in:
Alexis 2021-03-23 15:52:10 +01:00 committed by Nicolas Grekas
parent 9a8e2c2625
commit 2a196ca0dc
2 changed files with 12 additions and 2 deletions

View File

@ -167,7 +167,7 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
}
$intlDomain = $domain;
$suffixLength = \strlen(self::INTL_DOMAIN_SUFFIX);
if (\strlen($domain) > $suffixLength && false !== strpos($domain, self::INTL_DOMAIN_SUFFIX, -$suffixLength)) {
if (\strlen($domain) < $suffixLength || false === strpos($domain, self::INTL_DOMAIN_SUFFIX, -$suffixLength)) {
$intlDomain .= self::INTL_DOMAIN_SUFFIX;
}
foreach ($messages as $id => $message) {

View File

@ -69,7 +69,7 @@ class MessageCatalogueTest extends TestCase
$this->assertEquals($messages, $catalogue->all());
}
public function testAllIntICU()
public function testAllIntlIcu()
{
$messages = [
'domain1+intl-icu' => ['foo' => 'bar'],
@ -129,6 +129,16 @@ class MessageCatalogueTest extends TestCase
$this->assertEquals('bar', $catalogue->get('foo', 'domain88'));
}
public function testAddIntlIcu()
{
$catalogue = new MessageCatalogue('en', ['domain1+intl-icu' => ['foo' => 'foo']]);
$catalogue->add(['foo1' => 'foo1'], 'domain1');
$catalogue->add(['foo' => 'bar'], 'domain1');
$this->assertSame('bar', $catalogue->get('foo', 'domain1'));
$this->assertSame('foo1', $catalogue->get('foo1', 'domain1'));
}
public function testReplace()
{
$catalogue = new MessageCatalogue('en', ['domain1' => ['foo' => 'foo'], 'domain1+intl-icu' => ['bar' => 'bar']]);