PHP code example of cakephp / i18n

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

    

cakephp / i18n example snippets


use Cake\I18n\I18n;

I18n::setLocale('en_US');

use Cake\Core\Configure;

Configure::write('App.paths.locales', ['/path/with/trailing/slash/']);

echo __(
    'Hi {0,string}, your balance on the {1,date} is {2,number,currency}',
    ['Charles', '2014-01-13 11:12:00', 1354.37]
);

// Returns
Hi Charles, your balance on the Jan 13, 2014, 11:12 AM is $ 1,354.37

use Cake\I18n\I18n;
use Cake\I18n\Package;

I18n::translator('animals', 'fr_FR', function () {
    $package = new Package(
        'default', // The formatting strategy (ICU)
        'default', // The fallback domain
    );
    $package->setMessages([
        'Dog' => 'Chien',
        'Cat' => 'Chat',
        'Bird' => 'Oiseau'
        ...
    ]);

    return $package;
});

I18n::getLocale('fr_FR');
__d('animals', 'Dog'); // Returns "Chien"

$time = Time::now();
echo $time; // shows '4/20/14, 10:10 PM' for the en-US locale

echo Number::format(100100100);

echo Number::currency(123456.7890, 'EUR');
// outputs €123,456.79