Skip to content

Commit

Permalink
feat(core): \LastDragon_ru\LaraASP\Core\Helpers\Translator will not…
Browse files Browse the repository at this point in the history
… change keys with namespace (`::`).
  • Loading branch information
LastDragon-ru committed Nov 15, 2024
1 parent 5f3b801 commit df4e159
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/core/src/Helpers/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

/**
Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/Helpers/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
];
}
// </editor-fold>
Expand Down

0 comments on commit df4e159

Please sign in to comment.