PHP 中 INTL MessageFormatter 的命名参数
我想在传递给 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 起支持命名参数(参见此处),我用的
是4.2.1 独角兽在哪里? PHP 不支持 MessageFormatter 的命名参数? 也许还有其他选择吗?
I would like to use named arguments in a string passed to MessageFormater, like that
$fmt = new MessageFormatter("en_US", "My name id {my_name}");
$fmt->format(array('my_name' => 'John'));
When I running this code, I obtain the error message :
$fmt->getErrorMessage() returns
Number formatting failed: U_ILLEGAL_ARGUMENT_ERROR
Whereas
$fmt = new MessageFormatter("en_US", "My name id {0}");
$fmt->format(array(0 => 'John'));
works well.
icu-project website report that named arguments are supported since ICU 3.8 (Seen here), and I use the 4.2.1
Where is the unicorn? PHP doesn't support named arguments for MessageFormatter?
Maybe there is an alternative?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这在 intl 的未来(截至今天)版本中已修复。请参阅https://bugs.php.net/bug.php?id=61871 .
This is fixed in a future (as of today) version of intl. See https://bugs.php.net/bug.php?id=61871 .
是的,看来是这样。你想听什么?
更新:OP编辑他的问题后
请参阅 sprintf()
当然它没有任何基于本地的东西。
Yes, seems so. What do you want to hear?
Update: After the OP edited his question
See sprintf()
Of course it does not any local-based things.