Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Translate] add an intl MessageFormatter interpolator #892

Merged
merged 13 commits into from
Mar 18, 2019

Conversation

challet
Copy link
Contributor

@challet challet commented Mar 7, 2019

Hello!

  • Type: new feature

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the Contributing Guidelines?
  • I have checked that another pull request for this purpose does not exist.
  • I wrote some tests for this PR.

Small description of change:

  • add an Intl MessageFormatter interpolator, see formating guide and ICU documentation.
  • remove direct usage of MessageFormatter (and other interpolators core mechanism) from inside adapter implementations.
    • Breaking change : see list below, interpolators can be used instead.
    • Note : no tests were provided for the existing adapters.

Exemples :

  • direct usage :
use Phalcon\Translate\Interpolator\Intl;

$interpolator = new Intl('en_US'); // this interpolator must be locale aware
$stringFrom = 'I have {number_apples, plural, =0{no apples} =1{one apple} other{# apples}} and my name is {name}.';
echo $interpolator->replacePlaceholders($stringFrom, ['number_apples' => 1000,'name' => 'John']));
// I have 1,000 apples and my name is John.
  • through an adapter, with the interpolator option :
<?php
use Phalcon\Translate\Adapter\NativeArray;
use Phalcon\Translate\Interpolator\Intl;

$translate = new NativeArray([
    'interpolator' => new Intl('en_US'), // this interpolator must be locale aware
    'content' => ['hi-name' => 'Hello {name}, it\'s {time, number, integer} o\'clock'],
]);

$name = 'Henry';
$translate->_('hi-name', ['name' => $name, 'time' => 8]); // Hello Henry, it's 8 o'clock

Deprecations

  • Library/Phalcon/Translate/Adapter/Database useIcuMessageFormatter option
  • Library/Phalcon/Translate/Adapter/Mongo formatter option
  • Library/Phalcon/Translate/Adapter/Mongo setFormatter and format protected methods
  • Library/Phalcon/Translate/Adapter/ResourceBundle automatic use of MessageFormatter
  • Library/Phalcon/Translate/Adapter/Base setPlaceholders public function

@challet challet marked this pull request as ready for review March 8, 2019 11:46
@challet
Copy link
Contributor Author

challet commented Mar 8, 2019

Notifying contributors about parts being deprecated in this PR : @iGusev @YerlenZhubangaliyev @iborodikhin

@sergeyklay sergeyklay merged commit 32cb183 into phalcon:3.4.x Mar 18, 2019
@sergeyklay
Copy link
Contributor

Thank yoy

sergeyklay pushed a commit that referenced this pull request Jul 27, 2019
* #875: Swiftmailer and Twig are no longer required

Moved Swiftmailer and Twig to the Composer "suggest"

* Add new validator: ArrayInclusionIn

* Fix unit test

* Fix unit test - last test method

* Support for the TIMESTAMPDIFF

* Add options to ReCaptcha Validator to make it work with v3.

* Fixed PHPCS issues

* fix(oracle): Added missing interface method sharedLock

* Moved opening brace to newline as suggested

Co-Authored-By: lubber-de <[email protected]>

* Translate Adapter for multi-column csv (#890)

* [Translate] add an intl MessageFormatter interpolator (#892)

* Tidied up READMEs.

* Applied PSR2 to tests.

* Code standards.

* Tidied up Annotations.

* Tidied up codebase.
ruudboon pushed a commit to ruudboon/incubator that referenced this pull request Aug 30, 2019
ruudboon added a commit to ruudboon/incubator that referenced this pull request Aug 30, 2019
* phalcon#875: Swiftmailer and Twig are no longer required

Moved Swiftmailer and Twig to the Composer "suggest"

* Add new validator: ArrayInclusionIn

* Fix unit test

* Fix unit test - last test method

* Support for the TIMESTAMPDIFF

* Add options to ReCaptcha Validator to make it work with v3.

* Fixed PHPCS issues

* fix(oracle): Added missing interface method sharedLock

* Moved opening brace to newline as suggested

Co-Authored-By: lubber-de <[email protected]>

* Translate Adapter for multi-column csv (phalcon#890)

* [Translate] add an intl MessageFormatter interpolator (phalcon#892)

* Tidied up READMEs.

* Applied PSR2 to tests.

* Code standards.

* Tidied up Annotations.

* Tidied up codebase.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants