码迷,mamicode.com
首页 > 其他好文 > 详细

[React Intl] Render Content with Placeholders using react-intl FormattedMessage

时间:2017-07-28 20:57:42      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:react   hose   with   book   blog   date   content   view   hold   

Learn how to use react-intl to set dynamic values into your language messages. We’ll also learn how to pass in those values by using a values prop in the react-intl FormattedMessage component.

We‘ll also take a look at how to pass values with markup and still get all the benefits of translation.

 

Pass the ‘values‘ porp to the FormattedMessage:

          <h3>
            <FormattedMessage id="detail.author" values={{
              author: book.author
            }} />
          </h3>

 

For translations:

  ‘en-US‘: {
    detail: {
      author: ‘by {author}‘
    }
  },

 

It also supports pass in markdown as param:

              <p>
                <FormattedMessage id="detail.userRating" values={{
                  name: <strong>{review.name}</strong>,
                  rating: review.rating
                }}/><br />
                {new Date(review.date).toLocaleDateString()}
              </p>
  ‘en-US‘: {
    detail: {
      userRating: ‘{name} rated it: {rating} out of 5‘
    }
  },

 

[React Intl] Render Content with Placeholders using react-intl FormattedMessage

标签:react   hose   with   book   blog   date   content   view   hold   

原文地址:http://www.cnblogs.com/Answer1215/p/7252321.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!