PHP code example of tacoberu / fluent-intl

1. Go to this page and download the library: Download tacoberu/fluent-intl 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/ */

    

tacoberu / fluent-intl example snippets




use Taco\FluentIntl\FluentTranslator;
use Taco\FluentIntl\FluentResource;

$translator = new FluentTranslator("en-US");
$translator->addResource(new FluentResource('
-brand-name = Foo 3000
welcome = Welcome, {$name}, to {-brand-name}!
greet-by-name = Hello, { $name }!
emails =
    { $unreadEmails ->
        [1] You have one unread email.
       *[other] You have { $unreadEmails } unread emails.
    }
'));

$msg = $translator->getMessage("welcome");
dump($translator->formatPattern($msg->value, ["name" => "Anna"]));
// Welcome, Anna, to Foo 3000!

$msg = $translator->getMessage("emails");
dump($translator->formatPattern($msg->value, ["unreadEmails" => 5]));
// You have 5 unread emails.