From cb39a64fc8f0e4c1d533e37cc504f957e5861bbc Mon Sep 17 00:00:00 2001 From: Nyholm Date: Thu, 5 Sep 2019 18:46:09 +0200 Subject: [PATCH 1/2] Bugfix replace operation with null values --- Catalogue/Operation/ReplaceOperation.php | 7 +++++-- .../Catalogue/Operation/ReplaceOperationTest.php | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Catalogue/Operation/ReplaceOperation.php b/Catalogue/Operation/ReplaceOperation.php index 39b4bb8d..7d18743c 100644 --- a/Catalogue/Operation/ReplaceOperation.php +++ b/Catalogue/Operation/ReplaceOperation.php @@ -45,15 +45,15 @@ protected function processDomain($domain) foreach ($this->source->all($domain) as $id => $message) { $messageDomain = $this->source->defines($id, $intlDomain) ? $intlDomain : $domain; - $this->messages[$domain]['all'][$id] = $message; - $this->result->add([$id => $message], $messageDomain); if (!$this->target->has($id, $domain)) { // No merge required + $translation = $message; $this->messages[$domain]['new'][$id] = $message; $resultMeta = $this->getMetadata($this->source, $messageDomain, $id); } else { // Merge required + $translation = $message ?? $this->target->get($id, $domain); $resultMeta = null; $sourceMeta = $this->getMetadata($this->source, $messageDomain, $id); $targetMeta = $this->getMetadata($this->target, $this->target->defines($id, $intlDomain) ? $intlDomain : $domain, $id); @@ -68,6 +68,9 @@ protected function processDomain($domain) } } + $this->messages[$domain]['all'][$id] = $translation; + $this->result->add([$id => $translation], $messageDomain); + if (!empty($resultMeta)) { $this->result->setMetadata($id, $resultMeta, $messageDomain); } diff --git a/Tests/Unit/Catalogue/Operation/ReplaceOperationTest.php b/Tests/Unit/Catalogue/Operation/ReplaceOperationTest.php index 743f760a..c7fe36f8 100644 --- a/Tests/Unit/Catalogue/Operation/ReplaceOperationTest.php +++ b/Tests/Unit/Catalogue/Operation/ReplaceOperationTest.php @@ -54,6 +54,19 @@ public function testGetResultFromSingleDomain() ); } + public function testGetResultWithNullValues() + { + $this->assertEquals( + new MessageCatalogue('en', [ + 'messages' => ['a' => 'old_a', 'b' => 'old_b', 'c' => null], + ]), + $this->createOperation( + new MessageCatalogue('en', ['messages' => ['a' => null, 'c' => null]]), + new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b']]) + )->getResult() + ); + } + public function testGetResultWithMetadata() { $leftCatalogue = new MessageCatalogue('en', ['messages' => ['a' => 'new_a', 'b' => 'new_b']]); From 8385a3fd75d9a693446e7b6a29bd6539a026ee7a Mon Sep 17 00:00:00 2001 From: Nyholm Date: Thu, 5 Sep 2019 18:47:49 +0200 Subject: [PATCH 2/2] Added change log --- Changelog.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Changelog.md b/Changelog.md index ccc6c031..a0d50d32 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,12 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 0.9.1 + +### Fixed + +- Fixed issue with translations falsely marked as obsolete + ## 0.9.0 ### Added