Skip to content

Commit

Permalink
Merge pull request #1062 from spiral/fix-indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralbot committed Jan 15, 2024
1 parent e03ffd1 commit c87ea20
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
15 changes: 15 additions & 0 deletions tests/IndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c87ea20

Please sign in to comment.