|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-10-09 10:54 UTC] mh-php at outlook dot de
Description:
------------
Some combinations in the pattern string the MessageFormatter class completely fails returning null on object initialization and fails with bogus exception message on format().
Using the newest PECL module available.
intl
Internationalization support: enabled
version: PECL-3.0.0
ICU version: 55.1
ICU Data version: 55.1
Test script:
---------------
$msg = new MessageFormatter( "de_DE", "This is a number - {0,number}." );
var_dump( $msg->format( [ 654.987 ] ) );
$msg = new MessageFormatter( "de_DE", "This is an integer - {0,number,integer}." );
var_dump( $msg->format( [ 654.987 ] ) );
$msg = new MessageFormatter( "de_DE", "This is a combined number - {0,number} , {0,number,integer}." );
var_dump( $msg ); // $msg = null -> Fatal error: Call to a member function format() on a non-object, calling getErrorCode() is impossible
if( $msg !== null ) var_dump( $msg->format( [ 654.987 ] ) ); // never dumps anything
var_dump( MessageFormatter::formatMessage( "de_DE", "{itemCount}", [ "itemCount" => 5 ] ) );
var_dump( MessageFormatter::formatMessage( "de_DE", "{itemCount, plural, one {item} other {items} }", [ "itemCount" => 5 ] ) );
var_dump( MessageFormatter::formatMessage( "de_DE", "{itemCount} {itemCount, plural, one {item} other {items} }", [ "itemCount" => 5 ] ) ); // FAILS: why ...?
var_dump( MessageFormatter::formatMessage( "de_DE", "{itemCount,number} {itemCount, plural, one {item} other {items} }", [ "itemCount" => 5 ] ) ); // doesn't fail
var_dump( MessageFormatter::formatMessage( "en_US", "this is an unlocalized string {0,date}.", [ time() ] ) );
var_dump( MessageFormatter::formatMessage( "en_US", "this is an unlocalized string {0,date}.", [ new DateTime( "now" ) ] ) );
var_dump( MessageFormatter::formatMessage( "en_US", "this is an already localized string Oct 9, 2015.", [ time() ] ) );
$m = new MessageFormatter( "en_US", "this is an already localized string Oct 9, 2015." );
$m->format( [ new DateTime( "now" ) ] ); // Catchable fatal error: Object of class DateTime could not be converted to string
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 04:00:01 2025 UTC |
"This is a combined number - {0,number} , {0,number,integer}." - same numeric key specified twice. ->format( [ new DateTime( "now" ) ] ) - but you miss {0, date} in the format As well as other places - you use a wrong format or missing placeholders. Thanks.