1
0
Fork 0
mirror of https://github.com/archtechx/gloss.git synced 2025-12-12 11:14:04 +00:00

callable translation strings

This commit is contained in:
Samuel Štancl 2021-03-16 20:09:29 +01:00
parent 9948e4fd0f
commit 745513f251
3 changed files with 59 additions and 0 deletions

View file

@ -315,6 +315,18 @@ class GlossTest extends TestCase
$this->assertSame('YYY', gloss('test.abc', ['resource' => 'y']));
}
/** @test */
public function closures_can_be_used_in_translation_strings()
{
$this->addMessages('en', 'test', [
'foo' => fn () => 'bar',
'abc' => fn ($resource, $title) => Str::upper($resource) . ' ' . Str::lower($title),
]);
$this->assertSame('bar', gloss('test.foo'));
$this->assertSame('PRODUCT macbook pro', gloss('test.abc', ['resource' => 'product', 'title' => 'MacBook Pro']));
}
protected function addMessage(string $key, string $value, string $locale = 'en', string $group = 'test', string $namespace = null): void
{
$this->addMessages($locale, $group, [$key => $value], $namespace);