diff --git a/packages/core/src/Helpers/Translator.php b/packages/core/src/Helpers/Translator.php index 3cbd57e9..e755d170 100644 --- a/packages/core/src/Helpers/Translator.php +++ b/packages/core/src/Helpers/Translator.php @@ -9,6 +9,7 @@ use function array_splice; use function end; +use function str_contains; /** * Special wrapper around {@see TranslatorContract} to help translate package's messages. @@ -62,7 +63,11 @@ public function setLocale(string $locale): static { } protected function key(string $key): string { - return "{$this->getName()}::messages.{$key}"; + if (!str_contains($key, '::')) { + $key = "{$this->getName()}::messages.{$key}"; + } + + return $key; } /** diff --git a/packages/core/src/Helpers/TranslatorTest.php b/packages/core/src/Helpers/TranslatorTest.php index 421e7c42..191a64eb 100644 --- a/packages/core/src/Helpers/TranslatorTest.php +++ b/packages/core/src/Helpers/TranslatorTest.php @@ -201,6 +201,22 @@ static function (TestCase $test, string $currentLocale, string $fallbackLocale): ], 'unk', ], + 'translation exists (namespace)' => [ + 'translated text', + static function (TestCase $test, string $currentLocale, string $fallbackLocale): array { + return [ + $currentLocale => [ + 'test::should.be.translated' => '{1} one |[2,*] translated :value', + ], + ]; + }, + ['should.not.be.translated', 'test::should.be.translated', 'default'], + 2, + [ + 'value' => 'text', + ], + null, + ], ]; } //