-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Conversation
$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)) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
```php | ||
$username = 'Alexander'; | ||
echo \Yii::t('app', 'Hello, {username}!', array( | ||
'username' => $username, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latter.
* @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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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', '<') || |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
* 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. ...
Found a bug in PHP 5.5 in progress: https://bugs.php.net/bug.php?id=65920 Our wrapper fixes it. |
…bundled versions are always the same ones for the same PHP versions
… for the most complex test pattern
@cebe thanks a lot for handling ICU expressions grammar. Merged. |
My Pleasure :) |
{
and}
inYii::t
.