1. Go to this page and download the library: Download siilike/messageformat library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
siilike / messageformat example snippets
use Magneds\MessageFormat\MessageFormatter;
$formatter = new MessageFormatter('en', 'Found {count, plural, =0 {no result} =1 {one result} other {# results}}');
print $formatter->format(['count' => 0]); // Found no result
print $formatter->format(['count' => 1]); // Found one result
print $formatter->format(['count' => 2]); // Found 2 results
use Magneds\MessageFormat\MessageFormatter;
$formatter = new MessageFormatter('en', 'Found {0, plural, =0 {no result} =1 {one result} other {# results}}');
print $formatter->format([0]); // Found no result
print $formatter->format([1]); // Found one result
print $formatter->format([2]); // Found 2 results
use Magneds\MessageFormat\MessageFormatter;
$en = new MessageFormatter('en', 'Hello {audience}');
$es = new MessageFormatter('es', 'Hola {audience}');
$de = new MessageFormatter('de', 'Hallo {audience}');
use Magneds\MessageFormat\MessageFormatter;
$es = new MessageFormatter('es-ES', 'Por el pequeño precio de {price, number, currency} puedes comprar apps.');
print $es->format(['price' => 0.99]); // Por el pequeño precio de 0,99 € puedes comprar apps.
string MessageFormatter::getLocale(void)
use Magneds\MessageFormat\MessageFormatter;
$enNZ = new MessageFormatter('en-NZ', 'Hello {audience}');
$nlBE = new MessageFormatter('nl-BE', 'Hallo {audience}');
print $enNZ->getLocale(); // 'en_NZ'
print $nlBE->getLocale(); // 'nl_BE'
use Magneds\MessageFormat\MessageFormatter;
print MessageFormatter::parseMessage(
'en_US',
'{monkeys,number,integer} monkeys on {trees,number,integer} trees make {distribution,number} monkeys per tree',
'4,560 monkeys on 123 trees make 37.073 monkeys per tree'
); // ['monkeys' => 4560, 'trees' => 123, 'distribution' => 37.073],
array MessageFormatter::parse(string $value)
use Magneds\MessageFormat\MessageFormatter;
$nl = new MessageFormatter('nl', 'De {animal} {action} de {result} van de {target}');
$message = 'De kat krabt de krullen van de trap';
print $nl->parse($message); // ['animal' => 'kat', 'action' => 'krabt', 'result' => 'krullen', 'target' => 'trap']