2017 © Pedro Peláez
 

cakephp-plugin cakephp-intlless

Intlless plugin for CakePHP

image

chinpei215/cakephp-intlless

Intlless plugin for CakePHP

  • Tuesday, August 29, 2017
  • by chinpei215
  • Repository
  • 1 Watchers
  • 8 Stars
  • 221 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 11 % Grown

The README.md

Software License, (*1)

Intlless plugin for CakePHP

Intlless plugin is a plugin for CakePHP 3.x, which allows your application to work relatively well without intl extension., (*2)

Read this in other languages: English, 日本語, (*3)

Installing CakePHP3

If you don't have intl installed, you might have trouble installing CakePHP3 itself. You can install it with zip file, or with composer by changing configuration., (*4)

Installing with zip file

Download a release of CakePHP (cakephp-3-x-y.zip), and extract it. Set suitable permissions on your logs directory, tmp directory and its subdirectories., (*5)

Installing with composer

Execute the following command to pretend you have intl extension., (*6)

composer config --global platform.ext-intl 0.0.0

After that, you can execute create-project., (*7)

composer create-project --prefer-dist cakephp/app my_app_name

Installing Intlless plugin

After installing CakePHP3, let's install Intlless plugin., (*8)

Installing with zip file

Download a release of Intlless plugin (Source code). After extracting it, put it into your plugins directory, as "Intlless"., (*9)

Installing with git

If you want to install with git, execute the following command in your plugins directory., (*10)

git clone https://github.com/chinpei215/cakephp-intlless.git Intlless

Installing with composer

Execute the following command if you have not done it yet., (*11)

composer config --global platform.ext-intl 0.0.0

After that, you can install the plugin by the following command., (*12)

composer require --prefer-dist chinpei215/cakephp-intlless

Setting up Intlless plugin

Once you put this plugin, you need to load it in your config/bootstrap.php, but it would be better to do it near the front part of the file as much as possible. Because it is necessary to replace Cake\I18n-namespaced classes before the original classes loaded. Normally, it is best to do it just after loading config/app.php., (*13)

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]);

Note that the boostrap option and the autoload option are set to true in the above example. Since Intlless plugin needs to execute bootstrapping to replace Cake\I18n-namespaced classes, and if you have installed it with zip, it is necessary to use the autoloading feature of CakePHP., (*14)

Even if you have installed it with composer, make sure to set the bootstrap option to true., (*15)

In addition, you need to modify some code in your application. First, find a line where an error is thrown if intl extension is not loaded, and comment it out., (*16)

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

If useLocaleParser() call is found in your config/bootstrap.php, also comment it out. Intlless plugin doesn't support the feature., (*17)

// 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()*/;

Installation is end with this. You will see your application works relatively well without intl extension., (*18)

Limitations

Limitation of messaging functions

__() or other messaging functions cannot parse complex message formats., (*19)

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

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

In addition, they don't support any localization features., (*20)

Limitation of date and time functions

Cake\I18n\Time will be an alias of Intlless\Time. Intlless\Time is a sub-class of Cake\Chronos\MutableDateTime contained in Chronos, with different constructor. So you cannot call any methods not defined in the parent class, such as i18nFormat(), timeAgoInWords(), nice() and so on., (*21)

use Cake\I18n\Time;

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

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

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

The same can be said about Time helper. In addition, they don't support any localization features., (*22)

Cake\I18n\FrozenTime will be an alias of Intlless\FrozenTime. Intlless\FrozenTime is a sub-class of Cake\Chronos\Chronos with different constructor. So you cannot call any methods not defined in the parent class as well., (*23)

Cake\I18n\Date and Cake\I18n\FrozenDate will be an alias of Cake\Chronos\MutableDate and Cake\Chronos\Date, respectively., (*24)

Note that, CakePHP earlier than version 3.2, Cake\Chronos\MutableTime will be an alias of Carbon instead. Cake\I18n\FrozenTime will be undeclared., (*25)

Limitation of number functions

Cake\I18n\Number will be an alias of Intlless\Number. Intlless\Number is a small class that provides the following methods only., (*26)

  • precision()
  • toReadableSize()
  • toPercentage()
  • format()
  • formatDelta() (added in 0.2.0)

You cannot call any other methods not listed in the above., (*27)

use Cake\I18n\Number;

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

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

The same can be said about Number helper. In addition, they don't support any localization features., (*28)

Other limitations

  • You cannot use any other Cake\I18n-namespaced classes.
  • You cannot use Cake\ORM\Behavior\TranslateBehavior class.
  • You cannot use any functions using intl extension under the hood, such as Cake\Utility\Text::transliterate().

The Versions

29/08 2017

dev-master

9999999-dev

Intlless plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires

29/08 2017

1.0.2

1.0.2.0

Intlless plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires

25/03 2017

1.0.1

1.0.1.0

Intlless plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires

04/09 2016

1.0.0

1.0.0.0

Intlless plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires

04/09 2016

1.0.x-dev

1.0.9999999.9999999-dev

Intlless plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires

03/09 2016

0.2.0

0.2.0.0

Intlless plugin for CakePHP

  Sources   Download

The Requires

  • php >=5.4.16

 

The Development Requires

02/09 2016

0.1.0

0.1.0.0

Intlless plugin for CakePHP

  Sources   Download

The Requires

  • php >=5.4.16

 

The Development Requires