PHP code example of chinpei215 / cakephp-intlless

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

    

chinpei215 / cakephp-intlless example snippets


try {
    Configure::config('default', new PhpConfig());
    Configure::load('app', 'default', false);
} catch (\Exception $e) {
    exit($e->getMessage() . "\n");
}

//Configure::load('app_local', 'default');

// Here is the best place to load
Plugin::load('Intlless', ['bootstrap' => true, 'autoload' => true]);

if (!extension_loaded('intl')) {
    // Comment out this statement
    // trigger_error('You must enable the intl extension to use CakePHP.', E_USER_ERROR);
}

// Comment them out
// Type::build('date')->useLocaleParser();
// Type::build('datetime')->useLocaleParser();

// Comment out only useLocaleParser(), if the statement is like this
Type::build('time')
    ->useImmutable()
    /*->useLocaleParser()*/;

echo __('{0}%', 100);  // Prints 100%

echo __('{0,number,#,###}', 100); // Prints {0,number,#,###}

use Cake\I18n\Time;

$time = new Time('-12 hour');

echo $time->isYesterday(); // Works

echo $time->timeAgoInWords(); // Throws a fatal error

use Cake\I18n\Number;

echo Number::precision(1.2345, 3); // Prints 1.234

echo Number::currency(1000); // Throws a fatal error