React IntlReact 組件
React Intl 提供了一個 React 組件和用于國際化 React Web 應用的 Mixin。它提供一個格式化日期、數(shù)字、字符串消息的描述方式。
示例代碼:
var IntlMixin = ReactIntl.IntlMixin;
var FormattedMessage = ReactIntl.FormattedMessage;
var FormattedRelative = ReactIntl.FormattedRelative;
var PostMeta = React.createClass({
mixins: [IntlMixin],
render: function () {
return (
<FormattedMessage
message={this.getIntlMessage('post.meta')}
num={this.props.post.comments.length}
ago={<FormattedRelative value={this.props.post.date} />} />
);
}
});var post = {
date : 1422046290531,
comments: [/*...*/]
};var intlData = {
locales : ['en-US'],
messages: {
post: {
meta: 'Posted {ago}, {num, plural, one{# comment} other{# comments}}'
}
}
};
React.render( <PostMeta post={post} {...intlData} />,
document.getElementById('container')
);評論
圖片
表情
