From c87ea2044ccaf41a91a7037a96db71f98eb1e9e0 Mon Sep 17 00:00:00 2001 From: spiralbot Date: Mon, 15 Jan 2024 14:19:13 +0000 Subject: [PATCH] Merge pull request #1062 from spiral/fix-indexer --- src/Indexer.php | 4 +++- tests/IndexerTest.php | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Indexer.php b/src/Indexer.php index b215b8bb..28cf92bd 100644 --- a/src/Indexer.php +++ b/src/Indexer.php @@ -44,7 +44,9 @@ public function registerMessage(string $domain, string $string, bool $resolveDom } //Automatically registering - $this->catalogue->set($domain, $string, $string); + if (!$this->catalogue->has($domain, $string)) { + $this->catalogue->set($domain, $string, $string); + } $this->getLogger()->debug( \sprintf('[%s]: `%s`', $domain, $string), diff --git a/tests/IndexerTest.php b/tests/IndexerTest.php index 6a81e545..b9a22021 100644 --- a/tests/IndexerTest.php +++ b/tests/IndexerTest.php @@ -72,6 +72,21 @@ public function testIndexClasses(): void $this->assertTrue($catalogue->has('spiral', 'new-mess')); } + public function testRegisterMessageShouldNotOverrideMessages(): void + { + $catalogue = new Catalogue('fr'); + $catalogue->set('messages', 'hello', 'Bonjour'); + + $indexer = new Indexer(new TranslatorConfig([ + 'domains' => ['spiral' => ['spiral-*'], 'messages' => ['*']] + ]), $catalogue); + + $indexer->indexInvocations($this->tContainer()->get(InvocationsInterface::class)); + + $this->assertTrue($catalogue->has('messages', 'hello')); + $this->assertSame('Bonjour', $catalogue->get('messages', 'hello')); + } + protected function tContainer(): Container { $container = new Container();