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

[Work in progress] I18n icu #917

Merged
merged 21 commits into from
Oct 16, 2013
Merged

[Work in progress] I18n icu #917

merged 21 commits into from
Oct 16, 2013

Conversation

samdark
Copy link
Member

@samdark samdark commented Sep 28, 2013

  • Make tests pass on PHP 5.3 and PHP 5.4
  • add some more test for compex and edge cases
  • fix Yii code to use params w/o { and } in Yii::t.

$message = $this->applyPluralRules($message, $params[0], $language);
if (!isset($params['{n}'])) {
$params['{n}'] = $params[0];
if (class_exists('MessageFormatter', false) && preg_match('~{\s*[\d\w]+\s*,~u', $message)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean that every message translation will go through MessageFormatter? Will this cause performance issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. There's regexp that checks if it's something more than just plain interpolation and only then calls MessageFormatter.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) when pulling dafbeda on i18n-icu into b873f9f on master.

```php
$username = 'Alexander';
echo \Yii::t('app', 'Hello, {username}!', array(
'username' => $username,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it {username} or username? If the latter, then we should fix all other similar usage in Yii.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latter.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) when pulling abc0df6 on i18n-icu into b873f9f on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.11%) when pulling abc0df6 on i18n-icu into b873f9f on master.

* @param array $args The array of values to insert into the format string.
* @return string The pattern string with placeholders replaced.
*/
private static function replaceNamedArguments($pattern, $args)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need help with this one. See broken tests with PHP 5.3 or 5.4.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Came up with a solution to go through the pattern string and replace all relevant parts but leave out others. (3h work) Tests are passing :)

$params['{n}'] = $params[0];
if (class_exists('MessageFormatter', false) && preg_match('~{\s*[\d\w]+\s*,~u', $message)) {
$formatter = new MessageFormatter($language, $message);
if ($formatter === null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how can $formatter be null here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's null if pattern is incorrect and can't be consumed by ICU.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if this class is our extended version of MessageFormatter? Am I right that this is only possible with PHP internal classes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about it. Try with '' as a message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verified. works.

{
return (
!defined('INTL_ICU_VERSION') ||
version_compare(INTL_ICU_VERSION, '48.0.0', '<') ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check whether 48 is correct here. On my system I get 4.8.1.1 when doing echo INTL_ICU_VERSION . "\n";
PHP Version is 5.3.10-1ubuntu3.8

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows:

  • 50.1.2 on 5.5
  • 49.1.2 on 5.3
  • 49.1.2 on 5.4

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also confirm on Ubuntu PHP Version => 5.5.3-1ubuntu2
php -r "echo INTL_ICU_VERSION;"

4.8.1.1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samdark how is the intl version relevant for the fix?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like it is save to compare the number without dots:

4.8.1.1 -> 4811
50.1.2 -> 5012
49.1.2 -> 4912

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found the reason for this. They changed version numbering after 4.8 release: http://site.icu-project.org/download

@ghost ghost assigned cebe Oct 16, 2013
@coveralls
Copy link

Coverage Status

Coverage increased (+0.91%) when pulling 150b936 on i18n-icu into b873f9f on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.97%) when pulling 2eb5abb on i18n-icu into b873f9f on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.24%) when pulling bbcee32 on i18n-icu into b873f9f on master.

* master: (103 commits)
  fixed broken test after whitespace changes in view
  Removed the extra EOLs.
  I add new line in methods that render code in the head and for body
  GII update button style
  GII create object button style [skip ci]
  Fixes #980: Changed the default way of generating action URLs for ActionColumn.
  View default value for $params
  adjusted cubrid version in schema quote
  removed cubrid env from tavis.yml
  simplified cubrid db install on travis
  fixed cubrid schema test for pdo type
  fixed validator test break
  added cubrid specific pdo type casting
  Updated FileValidator tests
  Better AR connection init in tests
  Removed @codeCoverageIgnore
  no xss for attribute error messages that contain {value}
  Clientvalidation {value} was not what has been validated
  moved getPdoType() to Schema.
  optimized datepick js code.
  ...
@coveralls
Copy link

Coverage Status

Coverage increased (+0.51%) when pulling 677893e on i18n-icu into e574f10 on master.

@samdark
Copy link
Member Author

samdark commented Oct 16, 2013

Found a bug in PHP 5.5 in progress: https://bugs.php.net/bug.php?id=65920 Our wrapper fixes it.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.53%) when pulling da8f179 on i18n-icu into e574f10 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.53%) when pulling da8f179 on i18n-icu into e574f10 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.52%) when pulling bf7a084 on i18n-icu into e574f10 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.58%) when pulling 71e2dcc on i18n-icu into e574f10 on master.

samdark added a commit that referenced this pull request Oct 16, 2013
[Work in progress] I18n icu
@samdark samdark merged commit 3667e03 into master Oct 16, 2013
@samdark samdark deleted the i18n-icu branch October 16, 2013 22:20
@samdark
Copy link
Member Author

samdark commented Oct 16, 2013

@cebe thanks a lot for handling ICU expressions grammar. Merged.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 6b65ef5 on i18n-icu into e574f10 on master.

@cebe
Copy link
Member

cebe commented Oct 16, 2013

My Pleasure :)

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.

6 participants