Skip to content
Permalink
Browse files

Add more tests for message translation with parameters.

Update docs
  • Loading branch information...
SzollosMarketvision
SzollosMarketvision committed Apr 9, 2019
1 parent 20eeaf1 commit f59a77f09bcc7f177e85febf4517ed7089882a67
@@ -2,7 +2,7 @@

If you are using translator, then you can pass untranslated strings into this extensions, and it will automatically translate them into right phrase.

> NOTE: This extension have native support of [Kdyby/Translation](https://github.com/Kdyby/Translation)
> NOTE: We suggest use [Contributte/Translation](https://github.com/contributte/translation)
For translations, there are additional parameters, because you may need to change phrase according to count or replace some parameters.

@@ -18,7 +18,11 @@ $this->flashNotifier->message('Message text to display info about %replaceItWith

Translator will translate you message with depending on the *$count* variable and replace placeholders with defined parameters.

If you are using Kdyby/Translation you can pass [Kdyby\Translation\Phrase](https://github.com/Kdyby/Translation/blob/master/src/Kdyby/Translation/Phrase.php) object as message.
If you are using Contributte/Translation you can pass [domain.message.string](https://github.com/contributte/translation/tree/master/.docs) as message or u must put:
```php
'Message text to display info about %replaceItWithSomething%'
```
in [default domain file](https://github.com/contributte/translation/tree/master/.docs#neon)

## More

@@ -235,12 +235,33 @@ class NotifierTest extends Tester\TestCase
Assert::same('Hello', $flash->getMessage());
Assert::same('Title', $flash->getTitle());
$flash = $this->notifier->setMessage('messages.test.messageWithParam', Entities\IMessage::LEVEL_SUCCESS, null, null, ['name' => 'Name']);
Assert::true($flash instanceof Entities\IMessage);
Assert::same('Message with param Name', $flash->getMessage());
Assert::null($flash->getTitle());
$flash = $this->notifier->setMessage('Message text to display info about %replaceItWithSomething%', Entities\IMessage::LEVEL_SUCCESS, null, null, ['replaceItWithSomething' => 'Name']);
Assert::true($flash instanceof Entities\IMessage);
Assert::same('Message text to display info about Name', $flash->getMessage());
Assert::null($flash->getTitle());
$this->translator->setLocale('cs');
$flash = $this->notifier->setMessage('messages.test.hello', Entities\IMessage::LEVEL_SUCCESS, 'messages.test.title');
Assert::true($flash instanceof Entities\IMessage);
Assert::same('Ahoj', $flash->getMessage());
Assert::same('Titulek', $flash->getTitle());
$flash = $this->notifier->setMessage('messages.test.messageWithParam', Entities\IMessage::LEVEL_SUCCESS, null, null, ['name' => 'Name']);
Assert::true($flash instanceof Entities\IMessage);
Assert::same('Zpráva s parametrem Name', $flash->getMessage());
Assert::null($flash->getTitle());
$flash = $this->notifier->setMessage('Message text to display info about %replaceItWithSomething%', Entities\IMessage::LEVEL_SUCCESS, null, null, ['replaceItWithSomething' => 'Name']);
Assert::true($flash instanceof Entities\IMessage);
Assert::same('Zobrazení zprávy od Name', $flash->getMessage());
Assert::null($flash->getTitle());
}
/**
@@ -1,3 +1,5 @@
"Message text to display info about %replaceItWithSomething%": "Zobrazení zprávy od %replaceItWithSomething%"
test:
hello: "Ahoj"
title: "Titulek"
messageWithParam: "Zpráva s parametrem %name%"
@@ -1,3 +1,5 @@
"Message text to display info about %replaceItWithSomething%": "Message text to display info about %replaceItWithSomething%"
test:
hello: "Hello"
title: "Title"
messageWithParam: "Message with param %name%"

0 comments on commit f59a77f

Please sign in to comment.
You can’t perform that action at this time.