react-intl不会更改占位符的值

时间:2018-12-19 11:45:50

标签: javascript reactjs react-intl

我在这里做错什么了吗?

我正在按以下方式调用intl.formatMessage() API(https://github.com/yahoo/react-intl/wiki/API#formatmessage):

this.intl.formatMessage({id:'downloadRequest.success',values:{correlID:'test'}})

我的JSON文件中的字符串如下:

 "downloadRequest.success": "Your request was successfully submitted. Your reference ID is: {correlID}"

但是,当我查看该页面时,输出为:

Your request was successfully submitted. Your reference ID is: {correlID}

{correlID}不能代替提供给test的{​​{1}}值

1 个答案:

答案 0 :(得分:1)

您应该将值作为第二个参数传递。

this.intl.formatMessage({id:'downloadRequest.success'},{correlID:'test'})