Skip to content

Commit 584b8b9

Browse files
authored
Bug fix replace operation with null values (#333)
* Bugfix replace operation with null values * Added change log
1 parent ecf4909 commit 584b8b9

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Catalogue/Operation/ReplaceOperation.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ protected function processDomain($domain)
4545

4646
foreach ($this->source->all($domain) as $id => $message) {
4747
$messageDomain = $this->source->defines($id, $intlDomain) ? $intlDomain : $domain;
48-
$this->messages[$domain]['all'][$id] = $message;
49-
$this->result->add([$id => $message], $messageDomain);
5048

5149
if (!$this->target->has($id, $domain)) {
5250
// No merge required
51+
$translation = $message;
5352
$this->messages[$domain]['new'][$id] = $message;
5453
$resultMeta = $this->getMetadata($this->source, $messageDomain, $id);
5554
} else {
5655
// Merge required
56+
$translation = $message ?? $this->target->get($id, $domain);
5757
$resultMeta = null;
5858
$sourceMeta = $this->getMetadata($this->source, $messageDomain, $id);
5959
$targetMeta = $this->getMetadata($this->target, $this->target->defines($id, $intlDomain) ? $intlDomain : $domain, $id);
@@ -68,6 +68,9 @@ protected function processDomain($domain)
6868
}
6969
}
7070

71+
$this->messages[$domain]['all'][$id] = $translation;
72+
$this->result->add([$id => $translation], $messageDomain);
73+
7174
if (!empty($resultMeta)) {
7275
$this->result->setMetadata($id, $resultMeta, $messageDomain);
7376
}

Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44

5+
## 0.9.1
6+
7+
### Fixed
8+
9+
- Fixed issue with translations falsely marked as obsolete
10+
511
## 0.9.0
612

713
### Added

Tests/Unit/Catalogue/Operation/ReplaceOperationTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ public function testGetResultFromSingleDomain()
5454
);
5555
}
5656

57+
public function testGetResultWithNullValues()
58+
{
59+
$this->assertEquals(
60+
new MessageCatalogue('en', [
61+
'messages' => ['a' => 'old_a', 'b' => 'old_b', 'c' => null],
62+
]),
63+
$this->createOperation(
64+
new MessageCatalogue('en', ['messages' => ['a' => null, 'c' => null]]),
65+
new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b']])
66+
)->getResult()
67+
);
68+
}
69+
5770
public function testGetResultWithMetadata()
5871
{
5972
$leftCatalogue = new MessageCatalogue('en', ['messages' => ['a' => 'new_a', 'b' => 'new_b']]);

0 commit comments

Comments
 (0)