Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP的INTL MessageFormatter的命名参数_Php_Icu_Named Parameters_Intl - Fatal编程技术网

使用PHP的INTL MessageFormatter的命名参数

使用PHP的INTL MessageFormatter的命名参数,php,icu,named-parameters,intl,Php,Icu,Named Parameters,Intl,我希望在传递给MessageFormatter的字符串中使用命名参数,如下所示 $fmt = new MessageFormatter("en_US", "My name id {my_name}"); $fmt->format(array('my_name' => 'John')); 运行此代码时,我获得错误消息: $fmt->getErrorMessage() returns 数字格式设置失败:U\U非法\U参数\U错误 鉴于 $fmt = new MessageFor

我希望在传递给MessageFormatter的字符串中使用命名参数,如下所示

$fmt = new MessageFormatter("en_US", "My name id {my_name}");
$fmt->format(array('my_name' => 'John'));
运行此代码时,我获得错误消息:

$fmt->getErrorMessage() returns
数字格式设置失败:U\U非法\U参数\U错误

鉴于

$fmt = new MessageFormatter("en_US", "My name id {0}");
$fmt->format(array(0 => 'John'));
效果很好

icu项目网站报告称,自ICU3.8()以来,命名参数一直受到支持,我使用的是4.2.1

独角兽在哪里?PHP不支持MessageFormatter的命名参数?
也许还有别的选择?

是的,似乎是这样。你想听什么

更新:OP编辑了他的问题后

echo vsprintf('My name id %s', array('John'));


当然,它没有任何基于本地的东西。

这在将来(从今天起)的intl版本中是固定的。请参阅

我知道这条路。我的文本也被发送给翻译。我想避免%d,%s。翻译“我的名字是{My_name}”比翻译“我的名字是%s”更简单。这是一个不好的例子,因为这句话的意思很容易理解,但有时情况并非如此。