【发布时间】:2012-03-13 03:56:37
【问题描述】:
我想在传递给 MessageFormater 的字符串中使用命名参数,就像那样
$fmt = new MessageFormatter("en_US", "My name id {my_name}");
$fmt->format(array('my_name' => 'John'));
当我运行此代码时,我收到错误消息:
$fmt->getErrorMessage() returns
数字格式化失败:U_ILLEGAL_ARGUMENT_ERROR
而
$fmt = new MessageFormatter("en_US", "My name id {0}");
$fmt->format(array(0 => 'John'));
效果很好。
icu-project 网站报告称,自 ICU 3.8 (Seen here) 起支持命名参数,我使用的是 4.2.1
独角兽在哪里? PHP 不支持 MessageFormatter 的命名参数? 也许还有其他选择?
【问题讨论】:
标签: php icu named-parameters intl